装箱和拆箱
1 class Program 2 { 3 static void Main(string[] args) 4 { 5 //int n = 10; 6 //object o = n;//装箱 7 //int nn = (int)o;//拆箱 8 9 10 //ArrayList list = new ArrayList(); 11 //List<int> list = new List<int>(); 12 13 //Stopwatch sw = new Stopwatch(); 14 ////00:00:02.4370587 15 ////00:00:00.2857600 16 //sw.Start(); 17 /* 这个循环发生了100万次装箱操作 */ 18 //for (int i = 0; i < 10000000; i++) 19 //{ 20 // list.Add(i); 21 //} 22 //sw.Stop(); 23 //Console.WriteLine(sw.Elapsed); 24 //Console.ReadKey(); 25 26 //这个地方没有发生任意类型的装箱或者拆箱 27 //string str = "123"; 28 //int n = Convert.ToInt32(str); 29 30 //int n = 10; 31 //IComparable i = n;//发生装箱 32 } 33 }