how to sort List in c# / .net

前端 未结 4 1322
时光说笑
时光说笑 2021-01-11 10:25

I have a class PropertyDetails:

public class PropertyDetails
{

     public int Sequence { get; set; }

     public int Length { get; set; }

           


        
4条回答
  •  离开以前
    2021-01-11 10:49

    Using linq you can crate a new sorted list:

    list.OrderBy(x => x.Sequence).ToList();
    

    If you want to sort your current list, you can use a comparer:

    list.Sort((details1, details2) => details1.Sequence.CompareTo(details2.Sequence);
    

提交回复
热议问题