Home » C# String Compare() method

C# String Compare() method

by Online Tutorials Library

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 

You may also like