如何获取Nullable对象的原始类型?

时间:2012-04-13 01:37:29

标签: c# object nullable gettype

  

可能重复:
  Nullable type is not a nullable type?
  How to check if an object is nullable?

请参阅以下代码。有没有办法通过传递n作为参数来获得类似System.Nullable`1 [System.Int32]的东西?

static void Test()
{
  List<int> l = new List<int>();
  Nullable<int> n = new Nullable<int>( 1 );
  Console.WriteLine( l.GetType() ); // will output System.Collections.Generic.List`1[System.Int32]
  Console.WriteLine( n.GetType() ); // will output System.Int32. Why won't output something like System.Nullable`1[System.Int32] ?
}

0 个答案:

没有答案
相关问题