开发者

Is it possible to restrict a generic parameter to just accept nullable types? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Nullable type as a generic parameter possible?

Is creating a C# generic method that accepts (nullable) value type and reference type possible?

In c# I would like to restrict my generic method to accept only nullable types. Is that possible?

public 开发者_C百科T Method<T>() where T : somesortofnullablerestriction
{
   ...
}


You can do this.

public Nullable<T> Method<T>()
{
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜