我知道你会写:
要求确保泛型类型 T 有一个空构造函数。
我的问题是:
class GenericClass<T> where T : new()
{
}
要求确保泛型类型 T 有一个空构造函数。
我的问题是:
can you enforce that
T
has a constructor with a specific type of parameter? Like:class SingletonFactoryWithEmptyConstructor<T> where T : new(int)
can you enforce that
T
has a static function (let's say,void F()
) so that you can use this function inside the generic class? Like :class GenericClass<T> where T : void F() { void G () { T.F(); } }
I know you can specify that
T
implements an interface but I don't want that. I want to specify thatT
has a static function.