可能重复:
Nullable type as a generic parameter possible?
Is creating a C# generic method that accepts (nullable) value type and reference type possible?
在c#中,我想限制我的泛型方法只接受可空类型。这可能吗?
public T Method<T>() where T : somesortofnullablerestriction
{
...
}
答案 0 :(得分:1)
你可以这样做。
public Nullable<T> Method<T>()
{
}