我有一个简单的方法:
internal void run()
{
foreach (string file in Directory.GetFiles(Path).ToList()
.Where(x => DateTime.Today.Subtract(File.GetCreationTime(x)).Days > NumberOfDays))
{
File.Delete(file);
}
}
是否有可能摆脱foreach陈述?
答案 0 :(得分:-2)
Directory.GetFiles(Path).ToList()
.Where(x => DateTime.Today.Subtract(File.GetCreationTime(x)).Days > NumberOfDays)
.ForEach(File.Delete);