c# - Convert decimal? to double? -


i wondering best way (in sense of safer , succinct) convert 1 nullable type "compatible" nullable type.

specifically, converting decimal? double? can done using:

public double? converttonullabledouble(decimal? source) {     return source.hasvalue ? convert.todouble(source) : (double?) null; } 

is there better way this? maybe leveraging standard conversion?

built in casts win! tested in vs2012 and vs2010:

 decimal? numberdecimal = new decimal(5);   decimal? nulldecimal = null;  double? numberdouble = (double?)numberdecimal; // = 5.0  double? nulldouble = (double?)nulldecimal;     // = null 

just using explicit cast cast null null, , internal decimal value double. success!


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -