13
可能重复:
Determine if a generic param is a Nullable type如何检查泛型类型参数是否为空?
我试图确定一个类型参数为空。
public T Get<T>(int index)
{
var none=default(T);
var t = typeof(T);
BaseVariable v = this[index].Var;
if (T is Nullable) //compiler error
{
if (v == ...)
{
return none;
}
}
//....
}
我该怎么做?我试过t == typeof(Nullable)
,但总是会导致错误。
我想要发生的是使foo.Get<bool?>(1)
有时为空。
这是一个DUP http://stackoverflow.com/questions/5181494/determine-if-a-generic-param-is-a-nullable-type – Nix
@在VB中是Nix,所以也许不是一个骗局。我们将看到 – Earlz
解决方案使用C#和VB – Nix