是否可以將IEnumerable列表轉換爲BindingList集合?爲什麼我不能將IEnumerable <T>列表投射到BindingList <t>?
了IEnumerable列表類型對象的列表,例如:
IEnumerable<AccountInfo> accounts = bll.GetAccounts(u.UserName, u.Password);
而我PagingList只是延伸的BindingList:
public class PagingList<T>
{
public BindingList<T> Collection { get; set; }
public int Count { get; set; }
public PagingList()
{
Collection = new BindingList<T>();
Count = 0;
}
}
我只是想我的IEnumerable列表傳遞給呈現出來的方法與我的PagingControl清單:
protected void RenderListingsRows(PagingList<AccountInfo> list)
{
foreach (var item in list)
{
//render stuff
}
}
但似乎我不能施放兩個,任何人都可以指出我錯過了什麼?!
非常感謝
本
記住,一個強制轉換通常只是一個_check_來查看您所指的對象是否真的是您所說的類型。在這種情況下,它不是試圖以某種方式將一個不同的對象變形爲一個它尚未擁有的形狀。如果還不清楚,這篇文章可能會有所幫助:http://blogs.msdn.com/ericlippert/archive/2009/03/19/representation-and-identity.aspx – 2009-07-01 16:33:25