将IList转换为Collection

4

我需要将一个IList转换为Collection (System.Collections.ObjectModel)。

你该如何操作?

2个回答

8
Collection<MyClass> coll = new Collection<MyClass>(myIList);

4

只需使用构造函数:

IList<T> myList = ...
System.Collections.ObjectModel.Collection<T> omc = 
           new System.Collections.ObjectModel.Collection<T>(myList);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接