C# | Equals(String, String) Method
In C#, Equals(String, String) is a String method. It is used to determine whether two String objects have the same value or not. Basically, it checks for equality. If both strings have the same value, it returns true otherwise returns false. This method is different from Compare and CompareTo methods. This method compares two string on the basis of contents.
bool string.Equals(string str1, string str2)
Explanation: This method will take the two parameters in the form of string object and check them for equality. After checking, this method will return Boolean values. The return value type of this method is System.Boolean This method will return true if the value of str1 is the same as the value of str2 otherwise, false. If both str1 and str2 are null, then the method will return true.
Input: string str1 = "ProGeek 2.0"; string str2 = "ProGeek 2.0"; string.Equals(str1, str2) Output: True Input: string str3 = "GFG"; string str4 = "others"; string.Equals(str3, str4) Output: False
Below are the programs to demonstrate the above method :
- Program 1:
- Program 2: