1 static void Main(string[] args) 2 { 3 4 Stopwatch watch = new Stopwatch(); 5 watch.Start(); 6 Console.WriteLine("Time1 = " + watch.ElapsedMilliseconds); 7 IEnumerable<string> lsFiles = Directory.EnumerateFiles(@"D:\", "*.*", SearchOption.AllDirectories); 8 Console.WriteLine("Time2 = " + watch.ElapsedMilliseconds); 9 foreach (var item in lsFiles) 10 { 11 12 } 13 Console.WriteLine("Time3 = " + watch.ElapsedMilliseconds); 14 watch.Stop(); 15 watch.Restart(); 16 Console.WriteLine("Time3 = " + watch.ElapsedMilliseconds); 17 watch.Stop(); 18 }