开发者

C# Conversion Error Help

I am getting this error.

Error   1   Cannot implicitly convert type 'System.Collections.Generic.List<ModelBase.IModel>' to 'System.Collections.Generic.List<ModelBase.User>'

User inherits IModel, but I am not casting correctly.

I am trying to do something like this:

List<User> users = (List<User>)this.GetAll();
// GetAll() return type is List<IModel>
开发者_如何学Go


Try this:

List<User> users = this.GetAll().Cast<User>().ToList(); 
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜