Sort list by field (C#)

后端 未结 8 1136
一向
一向 2021-01-01 09:09

I have class like:

class SortNode
{
    public Int32 m_valRating = 0;

    public SortNode(Int32 valRating)
    {
        this.m_valRating = valRating;
    }         


        
相关标签:
8条回答
  • 2021-01-01 09:52

    Try this:

    refSortNodeList.Sort(new delgate(SortNode x, SortNode y)
       {
           return x.CompareTo(y);
        }
    );
    
    0 讨论(0)
  • 2021-01-01 09:59

    You can use Linq for basic sorts:

    refSortNodeList.OrderBy(n => n.m_valRating);
    

    If you need more complex sorting your will need to implement IComparable to use the built in sorting.

    0 讨论(0)
提交回复
热议问题