【发布时间】:2013-07-01 22:08:43
【问题描述】:
我有以下代码创建IEnumerable<T> 的扩展:
//http://stackoverflow.com/a/1779135/1180926
public static IEnumerable<T> SkipLast<T>(this IEnumerable<T> source, int n)
{
//.......
}
当我尝试将此应用于列表时:
public static void RemoveTwo(List<string> strList)
{
strList = strList.SkipLast(2);
}
我收到以下错误:
无法将类型“System.Collections.Generic.IEnumerable”隐式转换为 'System.Collections.Generic.List'。显式转换 存在(您是否缺少演员表?)
但是List<T>继承了IEnumerable<T>(src),那么它不应该也继承它的扩展方法吗?
【问题讨论】:
标签: c# inheritance extension-methods