我有下面的代碼,在.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中對此進行了更改(或已引入)的內容嗎?
有沒有關於這方面的任何文件?