using System.Collections.Generic;
using System.Diagnostics;
public static void Main() {
List<int> list = new List<int>();
for(var i = 0 ; i < 100000 ; i++) {
Stopwatch sw = new Stopwatch();
for(var i = 0 ; i < 10000 ; i++) ForEachList(list);
Console.WriteLine("foreach(var i in l) * 10000 {0}ms", sw.Elapsed);
for(var i = 0 ; i < 100 ; i++) ForList(list);
Console.WriteLine("for(var i = 0 ; i < l.Count ; i++) * 10000 {0}ms", sw.Elapsed);
for(var i = 0 ; i < 100 ; i++) IEnum(list);
Console.WriteLine("using (var i = l.GetEnumerator()) * 10000 {0}ms", sw.Elapsed);
public static void IEnum(IEnumerable<int> l) {
using (var i = l.GetEnumerator()) {
public static void ForList(List<int> l) {
for(var i = 0 ; i < l.Count ; i++) {
public static void ForEachList(List<int> l) {