当尝试将定义自定义泛型的类强制转换为子类时,我得到一个错误。我错了什么?
using System.Collections.Generic;
interface IStorageComponent { }
abstract class CollectionManager<T> where T : IStorageComponent { }
class Bar : IStorageComponent { }
class Foo : CollectionManager<Bar> { }
class Storage
{
static int Main(string[] args)
{
List<CollectionManager<IStorageComponent>> manager = new List<CollectionManager<IStorageComponent>>
{
new Foo() // <-- cannot convert from 'Foo' to 'CollectionManager<IStorageComponent>'
};
return 0;
}
}