Vignesh Kumar

Vignesh Kumar

  • NA
  • 1k
  • 401.6k

check if linq conditions has results

Oct 31 2016 2:39 AM

I am making some validations in an xml and remove certain elements based on date fields the below LINQ will do the job just fine.

XDocument newXML = XDocument.Load(new StringReader(xmlValue)); 
var q = from node in newXML.Descendants("Date") let attr = node.Value 
where attr != null && DateTime.ParseExact (attr, "dd-MM-yyyy", CultureInfo.InvariantCulture)
< DateTime.Today select node.Parent;   
q.ToList().ForEach(x => x.Remove());

How can I check whether this linq has identified and removed the items? OR
How can I load the results of newXML as an xml document?


Answers (2)