Users Pricing

forum

Home Forums Handle null exception in linq to xml query – MindStick

Handle null exception in linq to xml query

Anonymous User 2888 14 Aug 2014

var qXML = (from nm in xelement.Descendants("EmployeeFinance")

            where nm.Element("Status").Value.Contains(status) && int.Parse(nm.Element("Empersonal_Id").Value) == ele.EmpId

            select nm).SingleOrDefault();

Above is my sample code. Now there are instances where ele.EmpId will be present in the xml and instance where it will not be. How do i handle the null exception that is thrown when ele.EmpId is not found.


1 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md