Reputation: 469
Unable to cast object type "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; }
Why can not I?
Upvotes: 0
Views: 108
Reputation: 6719
Try myEnumerable.GetEnumerator()
Even better: return Products.GetEnumerator();
Upvotes: 5