假设您有 2 个课程:
public abstract class Foo<T> {
public abstract T DoSomething();
}
public class FooInt : Foo<int> {
public override int DoSomething() {
return 42;
}
}
我想将 FooInt 转换为 Foo
@Fildor 评论,像这样
public interface IFoo
{
}
public abstract class Foo<T> : IFoo
{
public abstract T DoSomething();
}
public class FooInt : Foo<int>
{
public override int DoSomething()
{
return 42;
}
}
public class FooDouble : Foo<double>
{
public override double DoSomething()
{
return 42.0;
}
}
List<IFoo> list = new List<IFoo>()
{
new FooInt(),
new FooDouble()
};