Determine the order

To find out order between two string values we can use the CompareTo method from string type.

public int CompareTo(string strB)

Return ValueCondition
< 0 This instance precedes strB.
0This instance has the same position in the sort order as strB.
>0This 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);



The output:

-1  |  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.