c# - convert decimal? in primitive decimal -


i want convert nullable decimal primitive decimal. how this. have done googling , found system.componentmodel.nullableconverter 1 of solution. not able figure out how use it.

decimal? offenceamount = 23; decimal primitive; primitive=offenceamount; // 

please help.

you can do:

if (offenceamount.hasvalue) {     primitive = offenceamount.value; } 

or, if want result default 0:

primitive = offenceamount.getvalueordefault(); 

or shortcut above:

primitive = offenseamount ?? 0; 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -