C# String Compare(String, String)
Description
String Compare(String, String)
compares two specified
String objects and returns an integer that indicates their relative position
in the sort order.
Syntax
String.Compare(String, String)
has the following syntax.
public static int Compare(
string strA,
string strB
)
Parameters
String.Compare(String, String)
has the following parameters.
strA
- The first string to compare.strB
- The second string to compare.
Returns
String.Compare(String, String)
method returns A 32-bit signed integer that indicates the lexical relationship between
the two comparands. Value Condition Less than zero strA is less than strB.
Zero strA equals strB. Greater than zero strA is greater than strB.
Example
The following code shows how to use String.Compare(String, String)
method.
using System;// w w w. java2 s. c o m
public class Example
{
public static void Main()
{
string s1 = "a";
string s2 = "animal";
Console.WriteLine("Comparison of '{0}' and '{1}': {2}",
s1, s2, String.Compare(s1, s2));
}
}
The code above generates the following result.