C#中的字典和数组之间有什么区别?
字典
字典是C#中键和值的集合。字典包含在System.Collection.Generics命名空间中。
声明字典-
IDictionary<int, int> d = new Dictionary<int, int>();
添加元素-
IDictionary<int, int> d = new Dictionary<int, int>(); d.Add(1,97); d.Add(2,89); d.Add(3,77); d.Add(4,88);
数组
数组存储相同类型元素的固定大小的顺序集合。它由连续的内存位置组成。最低地址对应于第一个元素,最高地址对应于最后一个元素。
定义数组-
int[] arr = new int[5];
初始化元素并将其设置为数组。
int[] arr = new int[10] {3, 5, 35, 87, 56, 99, 44, 36, 78};热门推荐
10 幼儿节日祝福语大全简短
11 婚礼仪式祝福语简短
12 发给导师的祝福语简短
13 岁岁祝福语简短独特
14 高考祝福语 简短12字
15 亲戚送行祝福语简短精辟
16 打游戏通关祝福语简短
17 死人新年祝福语简短句
18 中秋祝福语给父亲简短