using System; using System.Linq; using System.Collections; using System.Collections.Generic; class Class1 { static void Main(string[] args) { List<string> list = new List<string>(); for (int i = 0 ; i < 1000000; i ++) { list.Add(i.ToString()); } IEnumerable<string> enu = list; DateTime start = DateTime.Now; List<string> to_list = enu.ToList<string>(); Console.WriteLine("to_list : " + (DateTime.Now - start).Milliseconds); // => to_list : 7 start = DateTime.Now; if (typeof(List<string>) == enu.GetType()) { List<string> casted = (List<string>)enu; Console.WriteLine("casted " + (DateTime.Now - start).Milliseconds); // => casted 0 } start = DateTime.Now; String[] array = enu.ToArray<string>(); Console.WriteLine("array : " + (DateTime.Now - start).Milliseconds); // => array : 3 } }
の確認。
あー。こういうときは StopWatch 使えだったな。まあいいや。