Separate groups of objects based on their properties
- by Bevin
I want to separate an array of my custom object into several arrays, based on the values of their two properties. The struct looks like this:
struct MyStruct {
public string Person {
get;
set;
}
public string Command {
get;
set;
}
}
Now, if I have an array with a few objects:
{Person1, cmd1}
{Person1, cmd3}
{Person2, cmd3}
{Person3, cmd2}
{Person2, cmd4}
I want to be able to place them into one array for each person, that lists all of the commands for that person:
{Person1: cmd1, cmd3}
{Person2: cmd3, cmd4}
{Person3: cmd2}
I hope I've made it clear with my descriptions. I would assume that there is an elegant way to do this with LINQ, but I have no idea where to start.