开发者

Error casting in C#

开发者 https://www.devze.com 2023-03-05 00:13 出处:网络
I\'m getting the following error System.InvalidCastExce开发者_Python百科ption: Unable to cast object of type \'System.Int64\' to type \'System.String\'.

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

精彩评论

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