为什么我不能被演员?

den*_*den 0 c# ienumerable casting list

无法转换对象类型"System.Collections.Generic.List 1[NorthwindMVC3.Models.Product]" to the type of"System.Collections.Generic.IEnumerator1 [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; }
Run Code Online (Sandbox Code Playgroud)

为什么我不能?

Bal*_*nyi 5

尝试 myEnumerable.GetEnumerator()

更好的是: return Products.GetEnumerator();