1、Array(数组)html
一、申明时必需要指定数组长度。数组
二、数据类型安全。安全
申明数组以下:post
1 class Program 2 { 3 static void Main(string[] args) 4 { 5 6 Person[] personArray = new Person[3]; 7 8 personArray[0] = new Person { ID = 1, Name = "ZS" }; 9 personArray[1] = new Person { ID = 2, Name = "LS" }; 10 personArray[2] = new Person { ID = 3, Name = "WW" }; 11 12 } 13 } 14 15 public class Person{ 16 17 public int ID { get; set; } 18 19 public string Name { get; set; } 20 }
2、ArrayList性能
1.能够动态扩充和收缩对象大小。spa
2.可是类型不安全(须要装箱拆箱消耗性能)。code
1 class Program 2 { 3 static void Main(string[] args) 4 { 5 ArrayList al = new ArrayList(); 6 7 al.Add(new Person { ID = 1, Name = "ZS" }); 8 al.Add(new Studen { ID = 2, Name = "LS", Score = 100 }); 9 10 } 11 } 12 13 public class Person{ 14 15 public int ID { get; set; } 16 17 public string Name { get; set; } 18 } 19 20 public class Studen { 21 22 public int ID { get; set; } 23 24 public string Name { get; set; } 25 26 public float Score { get; set; } 27 }
3、Listhtm
结合Array和ArrayList的特性,List拥有能够扩充和收缩对象大小,而且实现类型安全。当类型不一致时编译就会报错。对象
1 class Program 2 { 3 static void Main(string[] args) 4 { 5 List<Person> list = new List<Person>(); 6 list.Add(new Person() { ID = 1, Name = "ZS" }); 7 list.Add(new Person() { ID = 2, Name = "LS" }); 8 } 9 } 10 11 public class Person{ 12 13 public int ID { get; set; } 14 15 public string Name { get; set; } 16 }