Error casting in C#
I'm getting the following error
System.InvalidCastExce开发者_Python百科ption: Unable to cast object of type 'System.Int64' to type 'System.String'.
in the code:
public static List<Category> getPopularCategories() {
clsCityPageDataContext cox = new clsCityPageDataContext();
var cats = from cat in cox.Categories select cat;
return cats.ToList<Category>().GetRange(0,10);
}
The problem is:
var cats = from cat in cox.Categories select cat;
return cats.ToList<Category>().GetRange(0,10);
replace with:
var cats = from cat in cox.Categories select cat;
return cats.ToList().GetRange(0,10);
精彩评论