C# - Sorting using Extension Method

前端 未结 4 984
野趣味
野趣味 2021-02-08 06:41

I want to sort a list of person say

List persons=new List();
persons.Add(new Person(\"Jon\",\"Bernald\",45000.89));
persons.Add(new P         


        
4条回答
  •  爱一瞬间的悲伤
    2021-02-08 07:42

    Do you really need the enums? I don't think that encapsulating your search logic in a method is much clearer or more DRY than just using linq methods:

    persons.OrderBy( p => p.FirstName );
    persons.OrderByDescending( p => p.Salary);
    

    etc.

提交回复
热议问题