Javatpoint Logo
Javatpoint Logo

C# String Compare()

The C# Compare() method is used to compare first string with second string lexicographically. It returns an integer value.

If both strings are equal, it returns 0. If first string is greater than second string, it returns 1 else it returns -1.

Rule

Signatures

Parameters

first: first argument represents string which is to be compared with second string.

second: second argument represents string which is to be compared with first string.

Return

It returns an integer value.


C# String Compare() Method Example

Output:

0
1
-1




Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA