一、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的更多相关文章

  1. 类 Array Arraylist List Hashtable Dictionary

    总结C# 集合类 Array Arraylist List Hashtable Dictionary Stack Queue  我们用的比较多的非泛型集合类主要有 ArrayList类 和 HashT ...

  2. c#中Array,ArrayList 与List<T>的区别、共性与转换

    本文内容来自我写的开源电子书<WoW C#>,现在正在编写中,可以去WOW-Csharp/学习路径总结.md at master · sogeisetsu/WOW-Csharp (gith ...

  3. Array,ArrayList、List<T>、HashSet<T>、LinkedList<T>与Dictionary<K,V>

    Array: 数组在C#中最早出现的.在内存中是连续存储的,所以它的索引速度非常快,而且赋值与修改元素也很简单. 但是数组存在一些不足的地方.在数组的两个数据间插入数据是很麻烦的,而且在声明数组的时候 ...

  4. 解析C#中[],List,Array,ArrayList的区别及应用

    [] 是针对特定类型.固定长度的. List 是针对特定类型.任意长度的. Array 是针对任意类型.固定长度的. ArrayList 是针对任意类型.任意长度的. Array 和 ArrayLis ...

  5. .net中的Array,ArrayList和List

    Array:任意类型,定长 ArrayList:任意类型,不定长 List:特定类型,不定长 Array和ArrayList是通过存储object类型实现可以存储任意类型数据,使用时需要拆箱和装箱

  6. [置顶] Array ArrayList LinkList的区别剖析

    这是一个面试中我们经常被问到的问题 Array.ArrayList.LinkList之间的区别:Array.ArrayList.LinkList均属于泛型的范畴,都用来存放元素,主要区别是Array是 ...

  7. Array,ArrayList 和 List<T>的选择和性能比较.

    Array Class Provides methods for creating, manipulating, searching, and sorting arrays, thereby serv ...

  8. C# 中的集合(Array/ArrayList/List<T>/HashTable/Dictionary)

    int [] numbers = new int[5]; // 长度为5,元素类型为 int.string[,] names = new string[5,4]; // 5*4 的二维数组byte[] ...

  9. Array,ArrayList,泛型List比较

    在C#中数组Array,ArrayList,泛型List都能够存储一组对象,但是在开发中根本不知道用哪个性能最高,下面我们慢慢分析分析. 一.数组Array 数组是一个存储相同类型元素的固定大小的顺序 ...

  10. C# 中的集合(Array/ArrayList/List<T>/HashTable/Dictionary)

    int [] numbers = new int[5]; // 长度为5,元素类型为 int. string[,] names = new string[5,4]; // 5*4 的二维数组 byte ...

随机推荐

  1. 通过Android studio手动触发Android 上层GC(垃圾回收)的方法

    1.打开android Studio, 2.菜单栏中点击"View"--"Tools Window"--"Profiler",可以看到对应的 ...

  2. ASP.NET通过更改Url进行页面传值

    这里,通过假数据,手动创建的一个类,然后创建的一个集合,放入下拉框,选好值以后,点确定 会在另一个页面产生对应的id,有不懂的欢迎评论 创建一个类: using System; using Syste ...

  3. Java实现 LeetCode 503 下一个更大元素 II

    503. 下一个更大元素 II 给定一个循环数组(最后一个元素的下一个元素是数组的第一个元素),输出每个元素的下一个更大元素.数字 x 的下一个更大的元素是按数组遍历顺序,这个数字之后的第一个比它更大 ...

  4. Java实现 LeetCode 242 有效的字母异位词

    242. 有效的字母异位词 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的字母异位词. 示例 1: 输入: s = "anagram", t = " ...

  5. Java实现蓝桥杯单位转换

    单位转换 [问题描述] BobLee最近在复习考研,在复习计算机组成原理的时候,遇到了一个问题.就是在计算机存储里面的单位转换. 我们都知道1MB=1024KB,1KB=1024B,1B=8bit,他 ...

  6. Linux 文件系统属性chattr权限

    chattr命令 格式:chattr [+-=] [选项] 文件或目录名,其中,+表示增加权限,-表示删除权限,=表示等于某权限(对超级用户root也有用),比如:chattr +i /project ...

  7. svg 贝塞尔曲线图解(记录)

    path路径绘制中,绘制贝塞尔曲线的命令包括: Q 二次贝赛尔曲线 x1,y1 x,y T 平滑二次贝塞尔曲线 x,y C 曲线(curveto) x1,y1 x2,y2 x,y S 平滑曲线 x2, ...

  8. MongoDB知识点总结

    一:MongoDB 概述    一.NoSQL 简介 1. 概念:NoSQL(Not Only SQL的缩写),指的是非关系型数据库,是对不同于传统的关系型数据库的数据库管理系统的统称.用于超大规模数 ...

  9. 如何在Centos7安装swoole的PHP扩展

    1. 下载swoole源代码包 wget -c https://github.com/swoole/swoole-src/archive/v2.0.8.tar.gz 2.tar -zxvf v2.0. ...

  10. 附022.Kubernetes_v1.18.3高可用部署架构一

    kubeadm介绍 kubeadm概述 参考附003.Kubeadm部署Kubernetes. kubeadm功能 参考附003.Kubeadm部署Kubernetes. 本方案描述 本方案采用kub ...