V
V
VanilaSpirit2020-10-27 14:31:10
C++ / C#
VanilaSpirit, 2020-10-27 14:31:10

C#. How to properly group from List to Dictionary?

There is data from the database that looks something like this:
CarId = 2, UserId = 44
CarId = 2, UserId = 45
CarId = 2, UserId = 46
CarId = 1, UserId = 90
CarId = 1, UserId = 91

I want to convert to the form CarId, List
Example:
CarId = 2, UserId = <44,45,46>
CarId = 1, UserId = <90,91>

How can this be done?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2020-10-27
@VanilaSpirit

list.ToLookup(l => l.CarId)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question