1

How can I get the maximum element(the object itself) in each group, rather than the number itself? I can only get the maximum value, not the object

        var maxValue = order.GroupBy(a => a.username).Select(a=>(a.Key, a.Max(k=>k.count)));
        Console.WriteLine("Max group = " + maxValue);
nilsK
  • 4,140
  • 1
  • 23
  • 39
chilo5432
  • 147
  • 1
  • 5
  • 2
    Does this [post](https://stackoverflow.com/questions/3188693/how-can-i-get-linq-to-return-the-object-which-has-the-max-value-for-a-given-prop) helps you ? – WilliamW Jan 03 '20 at 13:29
  • 2
    Does this answer your question? [How to use LINQ to select object with minimum or maximum property value](https://stackoverflow.com/questions/914109/how-to-use-linq-to-select-object-with-minimum-or-maximum-property-value) – Ismael Padilla Jan 03 '20 at 13:30
  • `Select` returns `IEnumerable`, you should get a single item from it (by key for example) – Pavel Anikhouski Jan 03 '20 at 13:37

0 Answers0