// CSharpList.cs - By Michael G. Workman // // This example C# console application builds and outputs a list and times the results // // This application freely distributable under terms of MIT open source license using System; using System.Collections.Generic; using System.Linq; namespace CSharpList { class CSharpList { static void Main(string[] args) { // timing var var watch = new System.Diagnostics.Stopwatch(); // create a list of integers var intList = new List(); // loop 1 hundred thousand times and add consecutive integer numbers to list // time the building and output of the list watch.Start(); for (int i = 0; i < 100000; i++) { intList.Add(i); } // output contents of list foreach (int element in intList) { Console.WriteLine(element); } watch.Stop(); // get the time in seconds double timeSeconds = watch.ElapsedMilliseconds / 1000.0; // output the results Console.WriteLine("C# time to build and display list: " + timeSeconds + " seconds"); Console.WriteLine("Number Elements: " + intList.Count()); Console.WriteLine(); Console.ReadLine(); } } }