C
craigkenisston
I'm working on someone else code I don't quite understand it.
It has a class with a method like :
private IEnumerable<Product> GetProducts(int count)
{
blah, blah
}
And I need to get an instance of the first object of that list:
Product prod = GetProducts(1);
I get a compile time error:
**************
"Cannot implicitly convert type
'System.Collections.Generic.IEnumerable<Products>' to 'Products'. An
explicit conversion exists (are you missing a
cast?) C:\Websites\BlogSK\Admin\Login.aspx.cs 24 18 C:\Websites\BlogSK\"
**************
I tried to:
Product prod = (Product)GetProducts(1);
And got it to compile, but then I get a runtime error:
"Unable to cast object of type
'System.Collections.Generic.List`1[Products]' to type 'Products'."
Any kind of help is appreciated.
It has a class with a method like :
private IEnumerable<Product> GetProducts(int count)
{
blah, blah
}
And I need to get an instance of the first object of that list:
Product prod = GetProducts(1);
I get a compile time error:
**************
"Cannot implicitly convert type
'System.Collections.Generic.IEnumerable<Products>' to 'Products'. An
explicit conversion exists (are you missing a
cast?) C:\Websites\BlogSK\Admin\Login.aspx.cs 24 18 C:\Websites\BlogSK\"
**************
I tried to:
Product prod = (Product)GetProducts(1);
And got it to compile, but then I get a runtime error:
"Unable to cast object of type
'System.Collections.Generic.List`1[Products]' to type 'Products'."
Any kind of help is appreciated.