【发布时间】:2021-12-30 07:10:20
【问题描述】:
我有一个名为 Foo 的抽象类,它是通用的。
还有一个名为Bar 的类,它也是通用的,但需要从Foo 派生T。但如果不为Foo 指定泛型类型,我就无法做到这一点,我不想这样做 - 我希望从Foo 派生的任何类都符合条件。
abstract class Foo<T> { }
class Bar<T> where T : Foo { }
// This gives me CS0305 - Using the generic type Foo<T> requires 1 type argument.
我确定我缺少某种超级明显的解决方案。
【问题讨论】:
-
这是你要找的东西:
class Bar<T> : Foo<T> { }? -
@Karoshee 不。我不希望
Bar派生自Foo。 -
@CaiusJard 哦,对不起,我明白你的意思。
Question应该是Foo。
标签: c#