-7

我有一个列表,我想按升序对 CategoryCounter、GroupCounter、QuestionCounter 进行排序。我怎样才能做到这一点?

public class CustomList
{

    private int _categorySequence = 0;
    private int _groupSequence = 0;
    private int _questionSequence = 0;
    private string _name = String.Empty;

    public string Name
    {
        get { return _name; }
        set { _name = value; }
    } 

    public int CategoryCouter
    {
        get { return _categorySequence; }
        set { _categorySequence = value; }
    }

    public int GroupCounter
    {
        get { return _groupSequence; }
        set { _groupSequence = value; }
    }

    public int QuestionCounter
    {
        get { return _questionSequence; }
        set { _questionSequence = value; }
    }
}
4

2 回答 2

1

您可以使用OrderBy后跟ThenBy

var result = MyCollection.OrderBy(x => x.CategoryCounter)
                         .ThenBy(y => y.GroupCounter)
                         .ThenBy(z => z.QuestionCounter);
于 2013-10-14T12:52:14.160 回答
0

嗯......我想,如果你可以做你想做的事情:

  1. 首先使用一些排序算法
  2. 如果发生碰撞,按第二个排序
  3. 如果第二个发生碰撞,则按第三个排序。
于 2013-10-14T12:50:51.857 回答