将数组转换为BindingList最简单快捷的方法是什么?
使用带有IList<T>
的BindingList
构造函数。
var binding = new BindingList<MyType>(myArray);
Be careful when using the BindingList(IList ..) constructor with an Array as the IList will be read-only.
Any attempts to add/remove from the BindingList will therefore throw a NotSupportedException as the IList can't handle the functionality as the Collection is read-only.
To create an editable BindingList you'll have to convert it to a list before using the IList constructor.
A nice description as to why Arrays are built from IList can be found here for some additional reading: Why array implements IList?
你正在寻找构造函数 :
var bl = new BindingList<YourClass>(arr);
you can try a foreach cycle:
public void AppenFromArray(T[] aSource)
{
if (aSource == null) { return; }
foreach (T el in aSource)
{
this.Add(el);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.