C# 中列表和陣列有什麼不同?


陣列儲存相同型別元素的固定大小順序集合,而列表是泛型集合。

定義列表 -

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};

更新於: 2020 年 6 月 21 日

8K+ 瀏覽量

開啟你的 職業生涯

透過完成課程獲得認證

開始學習
廣告
© . All rights reserved.