I'm trying to create a collection of collections, like a 2D array. Each collection (inside the main collection) will be the same type, though. It's just that we don't know what those types are.
for example:
a collection that contains:
- a list of cats
- a list of houses
- a list of SO questions.
so a collection with 3x collections inside.
Now, I'm trying the following C# code and getting a compile time error when I'm trying to do this:
IList<Foo> foos1 = new List<Foo>(); // e.g. Cats.
List<Foo> foos2= new List<Foo>(); // e.g. Houses.
var fails = new List<IList>
{
foos1 // Fails
};
var works = new List<IList>
{
foos2 // Works
};
Can someone please explain why this is?