Using LINQ with Action to delete old files
c#, linq
Solution
`Select()` is used to project items from `TSource` to `TResult`. In your case, you do not need `Select` because you're not projecting. Instead, use `List<T>`s `ForEach` method to delete files:
di.GetFiles("*.pdf").ToList().ForEach(deleter);
Problem
I would like to do something like ``` Action<FileInfo> deleter = f => { if (....) // delete condition here { System.IO.File.Delete(f.FullName); } }; DirectoryInfo di = new DirectoryInfo(_path); di.GetFiles("*.pdf").Select(deleter); // <= Does not compile! di.GetFiles("*.txt").Select(deleter); // <= Does not compile! di.GetFiles("*.dat").Select(deleter); // <= Does not compile! ``` in order to delete old files from a directory. But I do not know how to directly apply the delegate to the FilInfo[] without an explicit foreach (the idea listed above does not work of course). Is it possible?