How to know the maximum mass



  • Got a list.

    List<string> list = new List<string>();
    list.Add("10;abc");
    list.Add("14;hgg");
    list.Add("15;xxc");
    

    How do you know the maximum element of the list by weight to ; ?

    var rez = list.Select(x=>x.Split(';')[0]).Max();
    

    That's how the maximum element is found only without the second element.



  • It's easier to use the package. https://www.nuget.org/packages/morelinq/ :

    using MoreLinq;
    
    list.MaxBy(x => int.Parse(x.Split(';')[0]))
    

    It is possible without extraneous packages, a little less effective, through grading:

    list.OrderByDescending(x => int.Parse(x.Split(';')[0])).First();
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2