为什么我不能被铸造
本文关键字:不能 为什么 | 更新日期: 2023-09-27 18:28:28
无法强制转换对象类型"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; }
为什么我不能?
尝试myEnumerable.GetEnumerator()
更好:return Products.GetEnumerator();