I want to group a list of User by their according Group.
A user can be in multiple groups.
public class User
{
public string Username { get; set; }
public List<Group> Groups { get; set; }
}
The BusinessLogic returns me a List<User>.
Instead of Users have their Groups, I need to reform this list so Groups contains the Users.
Example:
Group 1:
- User 1
- User 2
Group 2:
- User 1
- User 3
Group 3:
- User 2
- User 3
I'm stuck on which extension method I need to use, so I'm not sure what to search for.
I would assume the GroupBy method but after that I'm lost :)