需引用 System.Collections。ArrayList arrayTest = new ArrayList(4); 指定初始容量 4。
arrayTest.Add("www."); arrayTest.Add("gosoa."); arrayTest.Add("com."); arrayTest.Add("cn");
Console.WriteLine(arrayTest.Capacity); // 4
arrayTest.Add("url"); // 第 5 個元素
Console.WriteLine(arrayTest.Capacity); // 8(自動倍增)
ArrayList arrayTest = new ArrayList(4);
arrayTest.Add("www."); arrayTest.Add("gosoa."); arrayTest.Add("com."); arrayTest.Add("cn");
// 輸出:www.gosoa.com.cn
arrayTest.Insert(0, "https://");
// 輸出:https://www.gosoa.com.cn
string[] stringArr = { "\n", "www.", "cnblogs.", "com" };
arrayTest.AddRange(stringArr);
// 輸出:https://www.gosoa.com.cn www.cnblogs.com
arrayTest.RemoveRange(4, 4);
// 僅剩:https://www.gosoa.com.cn
其他方法:Insert()、RemoveAt()、AddRange()、RemoveRange()。