Given two strings and we have to check whether strings are same or not?
string.CompareTo() Method
string.CompareTo() is a method of string class, it is used to compare two strings.
Syntax:
int string.CompareTo(string str);
Method returns 0, greater than 0 or less than 0.
Return values:
- 0 - If strings matched.
- >0 - First string is greatest on the basis of Unicode character.
- <<0 - First string is smallest on the basis of Unicode character.
-
C# program to compare two strings
Output