I have a sample class like this:
SampleClass
{
string code;
int id;
string name;
}
Valid data for the class would be:
SampleClass{code= "code1", id= 1, name= "name1"}
SampleClass{code= "code1", id= 1, name= "name2"}
SampleClass{code= "code2", id= 2, name= "name1"}
SampleClass{code= "code2", id= 2, name= "name2"}
SampleClass{code= "code2", id= 2, name= "name3"}
Now the question is, by using LINQ, I need to create a TestClass collection grouped on the SampleClass "id" field.
TestClass structure is as follows:
TestClass
{
string code;
List<string> names;
}
where "names" is a list of all SampleClass "name" values grouped by "id".
Based on the above SampleClass sample data, I would have 2 TestClass objects, one for id=1 and other for id=2
Thanks in advance