c# sort a list by a column alphabetically

后端 未结 2 1973
小蘑菇
小蘑菇 2021-01-25 10:49

I have a class defined and I write records to this class to a List. Having trouble sorting the list before I write an error report. I\'m trying to sort the list alphabetically b

相关标签:
2条回答
  • 2021-01-25 10:53

    Firstly its just

    List1.Sort();
    

    Sort method return nothing. It just sorts the list.

    Secondly if you want to sort based on a property do this

    List<Types> sortedlist = List1.OrderBy(x => x.finderror).ToList();
    
    0 讨论(0)
  • 2021-01-25 11:15

    I think you want List1 = List1.OrderBy( x => x.finderror ).ToList();

    0 讨论(0)
提交回复
热议问题