我有下面的代码,在.NET Framework版本编译4.0及以上版本:派生清单基地的IEnumerable
public abstract class MyBase { }
public class MyDerived : MyBase { }
public abstract class MyBaseCollection<T> : IList<T> where T : MyBase
{
protected readonly IList<T> deriveds = new List<T>();
public void Test()
{
// This line works in .NET versions 4.0 and above, but not in versions below.
IEnumerable<MyBase> bases = deriveds;
}
#region IList members with NotImplementedException
// ...
#endregion
}
public class MyDerivedCollection : MyBaseCollection<MyDerived> { }
但在.NET框架4.0以下我得到下面的行编译错误:
IEnumerable<MyBase> bases = deriveds;
无法隐式转换类型 'System.Collections.Generic.IList <牛逼>' 到 'System.Collections.Generic.IEnumerable'。存在明确的转换(您是否缺少演员?)
问题是在.NET 4.0中对此进行了更改(或已引入)的内容吗?
有没有关于这方面的任何文件?