C# 按3个值排序列表
我有一个列表,我想在CategoryCounter、GroupCounter、QuestionCounter上按升序排序。我怎样才能做到这一点C# 按3个值排序列表,c#,list,sorting,C#,List,Sorting,我有一个列表,我想在CategoryCounter、GroupCounter、QuestionCounter上按升序排序。我怎样才能做到这一点 public class CustomList { private int _categorySequence = 0; private int _groupSequence = 0; private int _questionSequence = 0; private string _name = String.Emp
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; }
}
}
嗯。。。我想,如果你:
不要犹豫在c#中使用搜索,它有内置的排序功能algorithms@wudzik当前位置我从未声称没有,是吗?那么为什么downvotenot矿山downvote,我刚刚发布了一条线索:)@wudzik-仅在某些框架版本中,这是一个假设,即它是3.5或更高版本。@据我所知,Steve列表。Sort在框架中的时间比自3.5以来的时间长:)根据MSDN自2.0以来您应该使用
。OrderBy(…)。ThenBy(…)。ThenBy(…)
@DominicKexel:谢谢,完成。
var result = MyCollection.OrderBy(x => x.CategoryCounter)
.ThenBy(y => y.GroupCounter)
.ThenBy(z => z.QuestionCounter);