博客园  :: 首页  :: 新随笔  :: 联系 :: 管理

转换 IList 到 IList

Posted on 2011-04-21 13:32  codingsilence  阅读(132)  评论(0编辑  收藏  举报

If you're sure that all of the elements inherit from T (or whatever type you're using)

IList<T> myList = nonGenericList.Cast<T>().ToList(); 

If you're not sure:

IList<T> myList = nonGenericList.OfType<T>().ToList(); 

Of course, you will need the System.Linq namespace:

using System.Linq;