c# - Which is Faster List.foreach or listString.GetEnumerator() -


I've written the following code to print item values ​​within the list. Now, I want to measure it, which will move faster with the move, I have a big list to deal with it. And please specify why you think it is better (if there is any proof)

How do I calculate the processing time? Manually making heavy inventory can be the only option?

  Public Zero Print Medoad (String Strip List Val) {Console.WriteLine (strPrintListVal); } Static zero main (string [] args) {program p1 = new program (); & Lt; String & gt; List string = new list & lt; String & gt; {"Rocks", "Stephens", "Manhatt", "Lexus", ":)"}; ListString.ForEach (p1.printMedod); Console.ReadKey (); }   

I can do the same thing using GetEnumerator:

  Fixed zero main (string [] args) {list & lt; String & gt; List string = new list & lt; String & gt; {"Rocks", "Stephens", "Manhatt", "Lexus", ":)"}; Var enumerator = listString.GetEnumerator (); While (counterclockwiseMyWidth ()) {var pair = enumerator.Current; Console.WriteLine (pair); } Console. Readkey (); }    

I want your way through the forEach list I am told, however, that the loop is faster than anything else:

 for  (int i = 0; i    

Comments