C# 中的列表和数组有什么区别?
csharpprogrammingserver side programming更新于 2025/10/13 13:07:17
数组存储的是固定大小且类型相同的元素的顺序集合,而列表是泛型集合。
定义列表 −
List<string7gt; myList = new List<string>();
要设置列表中的元素,需要使用 Add 方法 −
myList.Add("Audi");
myList.Add("BMW");
myList.Add("Chevrolet");
myList.Add("Hyundai");
定义数组 −
int[] arr = new int[5];
初始化数组并设置元素 −
int[] arr = new int[5] {23, 14, 11, 78, 56};

