【总结】Array、ArrayList、List
一、Array(数组)
1、申明时必须要指定数组长度。
2、数据类型安全。
申明数组如下:
1 class Program
2 {
3 static void Main(string[] args)
4 {
5
6 Person[] personArray = new Person[3];
7
8 personArray[0] = new Person { ID = 1, Name = "ZS" };
9 personArray[1] = new Person { ID = 2, Name = "LS" };
10 personArray[2] = new Person { ID = 3, Name = "WW" };
11
12 }
13 }
14
15 public class Person{
16
17 public int ID { get; set; }
18
19 public string Name { get; set; }
20 }
二、ArrayList
1.可以动态扩充和收缩对象大小。
2.但是类型不安全(需要装箱拆箱消耗性能)。
1 class Program
2 {
3 static void Main(string[] args)
4 {
5 ArrayList al = new ArrayList();
6
7 al.Add(new Person { ID = 1, Name = "ZS" });
8 al.Add(new Studen { ID = 2, Name = "LS", Score = 100 });
9
10 }
11 }
12
13 public class Person{
14
15 public int ID { get; set; }
16
17 public string Name { get; set; }
18 }
19
20 public class Studen {
21
22 public int ID { get; set; }
23
24 public string Name { get; set; }
25
26 public float Score { get; set; }
27 }
三、List
结合Array和ArrayList的特性,List拥有可以扩充和收缩对象大小,并且实现类型安全。当类型不一致时编译就会报错。
1 class Program
2 {
3 static void Main(string[] args)
4 {
5 List<Person> list = new List<Person>();
6 list.Add(new Person() { ID = 1, Name = "ZS" });
7 list.Add(new Person() { ID = 2, Name = "LS" });
8 }
9 }
10
11 public class Person{
12
13 public int ID { get; set; }
14
15 public string Name { get; set; }
16 }
转载于:https://www.cnblogs.com/Lv2014/p/5695005.html
【总结】Array、ArrayList、List的更多相关文章
- 类 Array Arraylist List Hashtable Dictionary
总结C# 集合类 Array Arraylist List Hashtable Dictionary Stack Queue 我们用的比较多的非泛型集合类主要有 ArrayList类 和 HashT ...
- c#中Array,ArrayList 与List<T>的区别、共性与转换
本文内容来自我写的开源电子书<WoW C#>,现在正在编写中,可以去WOW-Csharp/学习路径总结.md at master · sogeisetsu/WOW-Csharp (gith ...
- Array,ArrayList、List<T>、HashSet<T>、LinkedList<T>与Dictionary<K,V>
Array: 数组在C#中最早出现的.在内存中是连续存储的,所以它的索引速度非常快,而且赋值与修改元素也很简单. 但是数组存在一些不足的地方.在数组的两个数据间插入数据是很麻烦的,而且在声明数组的时候 ...
- 解析C#中[],List,Array,ArrayList的区别及应用
[] 是针对特定类型.固定长度的. List 是针对特定类型.任意长度的. Array 是针对任意类型.固定长度的. ArrayList 是针对任意类型.任意长度的. Array 和 ArrayLis ...
- .net中的Array,ArrayList和List
Array:任意类型,定长 ArrayList:任意类型,不定长 List:特定类型,不定长 Array和ArrayList是通过存储object类型实现可以存储任意类型数据,使用时需要拆箱和装箱
- [置顶] Array ArrayList LinkList的区别剖析
这是一个面试中我们经常被问到的问题 Array.ArrayList.LinkList之间的区别:Array.ArrayList.LinkList均属于泛型的范畴,都用来存放元素,主要区别是Array是 ...
- Array,ArrayList 和 List<T>的选择和性能比较.
Array Class Provides methods for creating, manipulating, searching, and sorting arrays, thereby serv ...
- C# 中的集合(Array/ArrayList/List<T>/HashTable/Dictionary)
int [] numbers = new int[5]; // 长度为5,元素类型为 int.string[,] names = new string[5,4]; // 5*4 的二维数组byte[] ...
- Array,ArrayList,泛型List比较
在C#中数组Array,ArrayList,泛型List都能够存储一组对象,但是在开发中根本不知道用哪个性能最高,下面我们慢慢分析分析. 一.数组Array 数组是一个存储相同类型元素的固定大小的顺序 ...
- C# 中的集合(Array/ArrayList/List<T>/HashTable/Dictionary)
int [] numbers = new int[5]; // 长度为5,元素类型为 int. string[,] names = new string[5,4]; // 5*4 的二维数组 byte ...
随机推荐
- Pycharm激活码测试有效,测试时间:2020-1-14可用
812LFWMRSH-eyJsaWNlbnNlSWQiOiI4MTJMRldNUlNIIiwibGljZW5zZWVOYW1lIjoi5q2j54mIIOaOiOadgyIsImFzc2lnbmVlT ...
- Java实现 蓝桥杯 算法提高 高精度减法(JDK方法)
试题 算法提高 高精度减法 问题描述 高精度减法 输入格式 两行,表示两个非负整数a.b,且有a > b. 输出格式 一行,表示a与b的差 样例输入 1234567890987654321 99 ...
- Java实现 LeetCode 149 直线上最多的点数
149. 直线上最多的点数 给定一个二维平面,平面上有 n 个点,求最多有多少个点在同一条直线上. 示例 1: 输入: [[1,1],[2,2],[3,3]] 输出: 3 解释: ^ | | o | ...
- Java实现 LeetCode 125 验证回文串
125. 验证回文串 给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写. 说明:本题中,我们将空字符串定义为有效的回文串. 示例 1: 输入: "A man, ...
- Java实现 LeetCode 44 通配符匹配
44. 通配符匹配 给定一个字符串 (s) 和一个字符模式 § ,实现一个支持 '?' 和 '*' 的通配符匹配. '?' 可以匹配任何单个字符. '*' 可以匹配任意字符串(包括空字符串). 两个字 ...
- 第一章03-Activity的启动模式
Activity的LaunchMode Android中提供了四中Activity的启动模式 1. standard 2. singleTop 3. singleTask 4. signleInsta ...
- k8s学习-存储
4.6.存储 4.6.1.ConfigMap 创建方式 文件夹/文件创建 mkdir dir cd dir cat > c1.properties <<EOF c1.name=c1 ...
- DML_The OUTPUT Clause
DML_The OUTPUT Clause /**/ ------------------------------------------------------------------------- ...
- 商城08——activeMQ 使用消息队列同步索引库
1. 课程计划 1.什么是MQ 2.MQ的应用场景 3.ActiveMQ的使用方法. 4.使用消息队列实现商品同步. 2. 同步索引库分析 方案一:在taotao-manager中,添加商品的业务 ...
- cb51a_c++_STL_算法_根据第n个元素排序nth_element
cb51a_c++_STL_算法_根据第n个元素排序nth_elementnth_element(b,n,e),比如最大的5个数排序,或者最小的几个数nth_element(b,n,e,p)对比:pa ...