C# String Compare() Method
C# String Compare()
Compare() method compares the characters of two strings.
The characters of the strings may be in lower case or upper case, this method discriminates between them.
Every character holds an ASCII value (an integer ranging from 0 to 127). For example, 'A' holds the ASCII value of 65 and 'a' holds the ASCII value of 97. So, in the comparison between two strings, their ASCII values are compared.
Compare() method starts comparison character by character starting from the first character until the characters in both strings are equal or a NULL character is encountered.
Note: The only difference between Compare() and CompareTo() method is the syntax.
|str2||Required||Specifies the string 2|
|str1||Required||Specifies the string 1|
|-1||If str1 is less than str2|
|0||If str1 is equal to str2|
|1||If str1 is greater than str2|
Hi Developers, we almost covered 90% of String functions and Interview Question on C# with examples for quick and easy learning.
We are working to cover every Single Concept in C#.
Please do google search for:
Join Our Channel
This channel is primarily useful for Full Stack Web Developer.