C
C
cicatrix2018-05-30 21:49:19
C++ / C#
cicatrix, 2018-05-30 21:49:19

How to create an anonymous type list with GroupBy?

There is a class

class Box
{
     // свойства
    public ProductName { get; set; }
    public IEnumerable<Item> GetItems()
    {
        // Возвращает список Items
    } // GetItems()
} // class Box

Now I have a list of these same Boxes, each of which has different content.
It is necessary to make a grouping a la SQL
SELECT ProductName, COUNT(Items) FROM BOXES GROUP BY ProductName
using LINQ:
There are IEnumerable Boxes
I do:
var list = Boxes.GroupBy( b=> ... ???? )
What should be in brackets?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2018-05-30
@cicatrix

In brackets - the field by which you group
var list = Boxes.GroupBy(b=> b.ProductName)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question