C# ?? null coalescing operator LINQ

karbon

New Member
I am trying to prevent having NULL values when I parse an XML file to a custom object using LINQ.I found a great solution for this on Scott Gu's blog, but for some reason it does not work for integers with me. I think I have used the same syntax but it seems I am missing something. Oh and for some reason it works when the node is not empty.Below is an extract of my code.\[code\]List<GrantAgresso> lsResult = (from g in xml.Element("root").Elements("Elementname") select new GrantAgresso() { Year = (int?)g.Element("yearnode") ?? 0, Subdomain = (string)g.Element("domainnode") ?? "" }).ToList();\[/code\]The errormessage is: \[quote\] Input string was not in a correct format.\[/quote\]If anyone has a clue as to what I'm doing wrong, please help :)
 
Back
Top