how to get type of a nullable type when the underlying value is null?

  • Thread starter Thread starter zdbdam
  • Start date Start date
Z

zdbdam

Guest
I tried to use following code to get "System.Decimal" but I received this undesirable exception! :(



decimal? x = null;
Console.WriteLine(x.GetType()); //I will get an NullReferenceException.


maybe one solution is:

decimal? x = null;
Console.WriteLine(x.GetValueOrDefault().GetType())

but i presume there is a better way.

Continue reading...
 
Back
Top