无法投射对象类型 “System.Collections.Generic.List
1[NorthwindMVC3.Models.Product]" to the type of"System.Collections.Generic.IEnumerator
1 [NorthwindMVC3.Models.Product]”。\
public IEnumerator<Product> GetEnumerator()
{
IEnumerable<Product> myEnumerable = Products.ToList();
return (IEnumerator<Product>) myEnumerable;
}
public class ProductsList : IEnumerable<Product>
{
public ProductsList()
{
Products =new List<Product>();
}
public List<Product> Products { get; private set; }
为什么我不能?
答案 0 :(得分:5)
尝试myEnumerable.GetEnumerator()
更好:return Products.GetEnumerator();