public static List<AccruedClass> validaccrued() { XDocument doc = XDocument.Load("Morgan.xml"); var ac = doc.Root.Elements("Positions") .Where(item => (float)item.Element("AccruedInterest") > 0.0)//some nodes doesnot contain "AccruedInterest" so its showing null error execption .Select(item => new AccruedClass { Cusip = item.Element("Cusip").Value != null ? item.Element("Cusip").Value : "", // Symbol = item.Element("symbol").Value, AccruedInterest = item.Element("AccruedInterest").Value != null ? Convert.ToDouble(item.Element("AccruedInterest").Value) : 0, PriceFactor = item.Element("PriceFactor").Value != null ? Convert.ToDouble(item.Element("PriceFactor").Value) : 0, Quantity = item.Element("Quantity").Value != null ? Convert.ToDouble(item.Element("Quantity").Value) : 0, }) .ToList(); List<AccruedClass> list_accr = ac.ToList<AccruedClass>(); return list_accr; }
float
float?
... .Where(item => (float?)item.Element("AccruedInterest") != null && (float?)item.Element("AccruedInterest") > 0.0) ...
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)