How do I sort an array of custom classes?

后端 未结 7 1016
暖寄归人
暖寄归人 2021-02-05 15:49

I have a class with 2 strings and 1 double (amount).

class Donator

  • string name
  • string comment
  • double amount

Now I have a A

7条回答
  •  情书的邮戳
    2021-02-05 16:34

    I always use the list generic, for example

    List MyList;
    

    then I call MyList.Sort

    MyList.Sort(delegate (Donator a, Donator b) {
       if (a.Amount < b.Amount) return -1;
       else if (a.Amount > b.Amount) return 1;
       else return 0; );
    

提交回复
热议问题