C#中Collection集合怎么转换List集合?请高手指教
3个回答
展开全部
public static class Extension//必须先声明一个静态类,类名随意
{
/// <summary>
/// IList转换为List
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="In"></param>
/// <returns></returns>
public static List<T> ToList<T>(this IList In) where T : class
{
List<T> list = new List<T>();
foreach (var i in In)
{
T t = i as T;
if (t != null)
{
list.Add(t);
}
}
return list;
}
{
/// <summary>
/// IList转换为List
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="In"></param>
/// <returns></returns>
public static List<T> ToList<T>(this IList In) where T : class
{
List<T> list = new List<T>();
foreach (var i in In)
{
T t = i as T;
if (t != null)
{
list.Add(t);
}
}
return list;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询