开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜