tags:

views:

114

answers:

1

I am trying to create a list of lists but am having trouble instantiating the list.

IList<IList<T>> allLists = List<List<T>>();

I am getting a compile error with this line.

+11  A: 

You'll have to instantiate a List of IList<T>, not a List of List<T>.

The reason is that by implementing IList<IList<T>> you are saying "Here is a list of some kind in which you can get or insert anything that implements IList<T>". Only objects of type List<T> can be inserted into List<List<T>>, so it is not allowed.

IList<IList<T>> allLists = new List<IList<T>>();
Greg
`new List<IList<T>>();`?
dtb
@dtb - Doh! Thanks
Greg