代码例如:
public Interface IArticle
{
int cid{get;set;}
string Name{get;set;}
string Content{get;set;}
...
}
public Class Article:IArticle
{
public int cid{get;set;}
public string Name{get;set;}
public string Content{get;set;}
public string Extension{get;set;}
...
}
/*
ArticleBiz.GetArticles(int cid) is select some items from database,return type:List<Article>
*/
List<IArticle> articleList=ArticleBiz.GetArticles(2).FindAll(p=>p.cid==cid)
例外:
Error 1 Cannot implicitly convert type
'System.Collections.Generic.List<Zm.Models.Article>'
to
'System.Collections.Generic.IList<Zm.Models.IArticle>'.
An explicit conversion exists (are you missing a cast?)
问题:我不想List<IArticle>
在GetArticles(..)
方法中将返回类型更改为。如何更改代码以List<Article>
成功转换List<IArticle>
?