代碼例如:如何轉換列表<Article>列出<IArticle>在C#3.5
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>
?