I've been working on something with alot of iteration (foreach) and now that everything is working I'd like to optimize it by changing it to link. Currently I am trying to translate this foreach code to LINQ
int count = 0;
foreach( string file in Directory.GetFiles( path ))
{
XDocument xdoc = new XDocument();
xdoc = XDocument.Load( file );
count += xdoc.Descendants( "PAGE" ).Count();
}
I'm not sure if it even possible however, here is the result of my trying :)
int count;
count = Directory.GetFiles( path ).Select( file => XDocument.Load( file ).Descendants( "PAGE" )).Select( result => result).Count() ;
I'd appreciate if someone could help but also explain me what's going on with the LINQ query.
Thank you =)