You can create a class say e.g. LISTOFNAMES that can have a public member names[] to be an array of
List <MyClass>
type. The size of the array can be passed as
an integer variable to the constructor of LISTOFNAMES(..) and at your code
you can instantiate each names[i] as an individual List.
The following example code shows the described way
// Add a public class LISTOFNAMES
public class LISTOFNAMES
{
public List<MyClass>[] names;
public LISTOFNAMES(int arsize)
{
this.names=new List<MyClass>[arsize];
}
}
Then at your code you have to instantiate at first an object of type LISTOFNAMES (supposing you have acquired the number of elements you need for the array names[index]) and then you have to instantiate each names[index] individually to be of
List <MyClass>
type.
Thus, you can add the following lines
//in your code
//suppose you have got a value for the number of names[] items say
// to be named nn (of type int), then you add the following
LISTOFNAMES lista=new LISTOFNAMES(nn);
// Then you add..
for(int i=0;i<nn;i++)
{
lista.names[i]=new List<MyClass>();
}
//Now you can use individually the lista.names[index] objects,
// for example like
lista.names[0].Add(new MyClass(...));
lista.names[1].Add(new MyClass(...));
etc
Alternatively, you can simply instantiate an array object of type
List<MyClass>[]
and then instantiate each item separately. e.g Having acquired the array size to
the "ar_size" being an int variable e.g.
int ar_size=table.Rows.Count;
you can use the following
List<MyClass>[] names=new List<MyClass>[ar_size];
for(int i=0;i<ar_size;i++)
{
names[i]=new List<MyClass>();
}
And then fill each object names[index] , like the following
names[0].Add(new MyClass(...));
names[1].Add(new MyClass(...));
etc.
Hope these help.
SelectMany()withToList()might do the job.Dictionary<string, List<MyClass>>or something to that effect. The key would be what you use to access the list for that name and add your class to it. Obviously you would also need to find a way to prevent issues if two people have the same name but hopefully this gave you enough of a hint to point you in the right direction...