【问题标题】:Cast an IList to a Collection将 IList 强制转换为集合
【发布时间】:2010-05-04 14:11:39
【问题描述】:

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

你是怎么做的?

【问题讨论】:

    标签: c# collections ilist


    【解决方案1】:
    Collection<MyClass> coll = new Collection<MyClass>(myIList);
    

    【讨论】:

      【解决方案2】:

      只需使用构造函数:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-10-30
        • 1970-01-01
        • 1970-01-01
        • 2018-11-02
        • 1970-01-01
        • 2014-05-02
        • 2015-02-17
        相关资源
        最近更新 更多