C # List of collective ordering

It is noted here, that is greater than the return is greater than 0, returns to less than less than, equal to, equal to 0 returns

class WithDomain : IComparable
    {
       public string username, cn, ou, office, desc;
       public int CompareTo(object obj)
       {
           //throw new NotImplementedException(); 
           WithDomain wd = obj as WithDomain;
           string ou1 = this.ou;
           string ou2 = wd.ou; 
           if (ou1.CompareTo(ou2) > 0)
               return 1;
           else if (ou1.CompareTo(ou2) == 0)
               return 0;
           else
               return -1;
       }
    }

List<WithDomain> comparaDomain = new List<WithDomain>();
comparaDomain.Sort();
Published 48 original articles · won praise 3 · views 20000 +

Guess you like

Origin blog.csdn.net/chscomfaner/article/details/82803888