开发者

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜