如何将IList<Customer>
列表投射到BindingList<Customer>
?
答案 0 :(得分:70)
var yourList = new List<Customer>();
var listBinding = new BindingList<Customer>(yourList);
您不需要进行演员表,只需提供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
:因此IBindingList
与IList
共享所有属性和功能签名。因此,IList
实施可以很容易地适应&#34; IBindingList
实施。