开发者

How can I instantiate a IList<T> of nested IList<T>?

开发者 https://www.devze.com 2023-01-16 04:01 出处:网络
I am trying to create a list of lists but am having 开发者_开发问答trouble instantiating the list.

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.


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>>();
0

精彩评论

暂无评论...
验证码 换一张
取 消