什么是C#中的动态数组?
动态数组是可增长的数组,并且比静态数组具有优势。这是因为数组的大小是固定的。
要在C#中动态创建数组,请使用ArrayList集合。它表示可以单独索引的对象的有序集合。它还允许动态分配内存,添加,搜索和排序列表中的项目。
以下是显示如何在C#中动态创建数组的示例-
示例
using System;
using System.Collections;
namespace Demo {
class Program {
static void Main(string[] args) {
ArrayList al = new ArrayList();
al.Add(577);
al.Add(286);
Console.WriteLine("Count: {0}", al.Count);
Console.Write("List: ");
foreach (int i in al) {
Console.Write(i + " ");
}
Console.WriteLine();
Console.ReadKey();
}
}
}输出结果
Count: 2 List: 577 286
热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短