I’m new to LINQ. My XML:
<Config>
<remainingDays>7</remainingDays>
</Config>
How to get 7 using LINQ?
I’ve tried the following and none helps:
XElement doc = XElement.Load("Config.xml");
remainDay = Convert.ToInt32(doc.Element("remainingDays").Value);
remainDay = Convert.ToInt32((from ele in doc.Elements()
let e = ele.Element("remainingDays")
select e));
remainDay = Convert.ToInt32((from el in doc.Descendants("remainingDays")
select el).First());
Updated.
remainDay is a int. I want to get the value of day in XML and assign to remainDay
This will help you get the value
7, Now you can parse it usingint.Parseand assign to remainDay.