开发者

C# Conversion Error Help

开发者 https://www.devze.com 2023-03-18 10:38 出处:网络
I am getting this error. Error1Cannot implicitly convert type \'System.Collections.Generic.List<ModelBase.IModel>\' to \'System.Collections.Generic.List<ModelBase.User>\'

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

精彩评论

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

关注公众号