c# dictionary,list排序

时间:2021-09-01 23:03:35

Dictionary Key排序

Dictionary<string, string> dct= new Dictionary<string, string>();

Dictionary<string, string> dctNew = dct.OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value);

list Key排序

Public class student{

    public int grade
{
set;
get;
} public int age
{
set;
get;
} public string name
{
set;
get;
}
} List<student> students = new List<student>();
students.OrderBy(x=>x.grade).ThenBy(x=>x.age);