The C# Equals function is employed to verify if two designated String objects possess identical values. If both strings contain the same value, it will return true; otherwise, it will return false.
In simpler terms, it is employed to evaluate two strings based on their content.
Signature
Example
public bool Equals(String str)
public static bool Equals(String, String)
public override bool Equals(Object)
public static bool Equals(String, String, StringComparison)
public bool Equals(String, StringComparison)
Parameter
str: it is a string object.
Return
It returns boolean value either true or false.
C# String Equals Method Example
Example
using System;
public class StringExample
{
public static void Main(string[] args)
{
string s1 = "Hello";
string s2 = "Hello";
string s3 = "Bye";
Console.WriteLine(s1.Equals(s2));
Console.WriteLine(s1.Equals(s3));
}
}
Output:
Output
True
False