<分区>
Possible Duplicate:
Determine if a generic param is a Nullable type
我正在尝试确定类型参数是否可为 Nullable。
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)
有时为空。