如何在C#中动态创建数组?
动态数组是可增长的数组,并且比静态数组具有优势。这是因为数组的大小是固定的。
要在C#中动态创建数组,请使用ArrayList集合。它表示可以单独索引的对象的有序集合。它还允许动态分配内存,添加,搜索和排序列表中的项目。
以下示例显示了如何在C#中动态创建数组。
示例
using System;
using System.Collections;
namespace CollectionApplication {
class Program {
static void Main(string[] args) {
ArrayList al = new ArrayList();
al.Add(99);
al.Add(47);
al.Add(64);
Console.WriteLine("Count: {0}", al.Count);
Console.Write("List: ");
foreach (int i in al) {
Console.Write(i + " ");
}
Console.WriteLine();
Console.ReadKey();
}
}
}输出结果
Count: 3 List: 99 47 64
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短