将IList <t>转换为BindingList <t> </t> </t>

时间:2013-02-19 09:00:00

标签: c# list generics casting bindinglist

如何将IList<Customer>列表投射到BindingList<Customer>

5 个答案:

答案 0 :(得分:70)

var yourList = new List<Customer>();
var listBinding = new BindingList<Customer>(yourList);

BindingList Constructors

您不需要进行演员表,只需提供BindingList<T>类构造函数IList<T>即可。

答案 1 :(得分:8)

不幸的是,你无法将IList强制转换为其中的东西。但是,只需将IList传递给构造函数,就可以非常轻松地创建一个新的BindingList。

BindingList<Customer> bindingList = new BindingList<Customer>(yourIList);

答案 2 :(得分:6)

BindingList构造函数接受IList参数,使用它:

var binding = new BindingList<Customer>(list); //where list is type of IList<Customer>

答案 3 :(得分:5)

        IList<Customer> list = new List<Customer>();

        var bindingList = new BindingList<Customer>(list);

答案 4 :(得分:1)

其他信息:IBindingList继承自IList:因此IBindingListIList共享所有属性和功能签名。因此,IList实施可以很容易地适应&#34; IBindingList实施。