I’m building an XML Deserializer for a project and I run across this type of code situation fairly often:
var myVariable = ParseNDecimal(xml.Element('myElement')) == null ? 0 : ParseNDecimal(xml.Element('myElement')).Value;
Is there a better way to write this statement?
EDIT : Perhaps I should have clarified my example as I do have a helper method to parse the string into a decimal.
You can use extension method:
EDIT:
The ‘universal’ solution: