To find out order between two string values we can use the CompareTo method from string type.
public int CompareTo(string strB)
| Return Value | Condition |
|---|---|
| < 0 | This instance precedes strB. |
| 0 | This instance has the same position in the sort order as strB. |
| >0 | This instance follows strB. -or- strB is null. |
using System;
class Program
{
static void Main(string[] args)
{
string s1 = "abc";
string s2 = "def";
int result = s1.CompareTo(s2);
Console.WriteLine(result);
}
}
The output:
-1
java2s.com | | Contact Us | Privacy Policy |
| Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
| All other trademarks are property of their respective owners. |