My current project (C# 3.5) has a lot of code like this (elem is an instance of XElement):
textbox1.Text = elem.Element("TagName") == null ? "" : elem.Element("TagName").Value;
Is there any way to write the same thing without repeating a call elem.Element() and without use of extension methods?
Maybe using lambdas? (But I cannot figure out how.)
XElement has a explicit conversion to String (and a bunch of other types) that will actually call .Value.
In otherwords you can write this:
i think this will return null if the actual element is null as well
-edit-
verified,
here is an example:
nwill be null after this.