I change my question. I want to know if with Linq can I get the same result as my code under. I have a folder with many pdf files. I need to group all files with date creation less then 10 seconds and merge these files.
I did the code but I want to know if I can do it with Linq.
My code is :
_period = 10;
DirectoryInfo di = new DirectoryInfo(_path);
List<FileInfo> files = di.GetFiles().OrderByDescending(d => d.CreationTime).ToList();
List<String> pdffiles = new List<String>();
if (files.Count > 0)
{
DateTime previous = files.FirstOrDefault().CreationTime;
TimeSpan delay = new TimeSpan(0, 0, _period);
foreach (var file in files)
{
if (file.CreationTime - previous <= delay)
pdffiles.Add(file.FullName);
}
}
I want to know there is a way with Linq to get the same result without a loop? Hope my code is more explicit than my description.
Thank you. Karim.