数组结构:node
Array :在内存上是连续分配的,并且元素类型是一致的;数组
特色:是读取快 能够坐标访问 可是增删慢,长度不能变安全
好比 int[] intArray=new int[20]; intArray[3]=10;数据结构
ArrayList:在内存上是连续分配的,元素没有类型限制,任何元素都是当成object处理的,若是是值类型,会有装箱操做spa
不定长度的 Add增长长度 索引赋值不会增长长度;读取快 增删慢;线程
ArrayList arrayList=new ArrayList();排序
arrayList.Add("001");索引
arrayList.Add("002");接口
arrayList.Remove("Eleven");队列
array[2]=32;
//删除数据
List:核心也是Array 内存上是连续分配的 能够用索引访问 不定长度 ;泛型,保证类型安全,避免装箱拆箱;读取快,增删慢;
List<string> stringList=new List<string>();
stringList.Add("001");
链表类型
LinkedList:泛型的,链表 元素不连续分配,每一个元素都有记录先后节点;
不能经过坐标访问, 找元素,只能遍历,查找不方便;增删比较方便;
LinkedList<int> linkedList=new LinkedList<int>();
linkedList.AddFirst(1);
linkedList.AddLast(10);
bool isContain=linkedList.Contains(123);
LinkedListNode<int> node123=linkedList.Find(123);
linkedList.AddBefore(node123,10);
linkedList.AddAfter(node123,11);
linkedList.Remove(123);
linkedList.RemoveFirst();
linkedList.RemoveLast();
Queue: 队列,就是链表, 先进先出, 如任务延迟执行,A不断地写入任务 B不断获取任务去执行;
Queue<int> numbers=new Queue<int>();
numbers.Enqueue(1);
numbers.Enqueue(2);
numbers.Enqueue(3);
numbers.Dequeue();//移除
numbers.Peek();//不移除
Stack: 栈,是链表, 先进后出
Stack<int> numbers=new Stack<int>();
numbers.Push(1);
numbers.Push(2);
numbers.Push(3);
numbers.Push(4);
numbers.Pop();//读取并移除
numbers.Peek();//读取不移除
集合Set
HashSet:hash分布 元素间没有关系 动态增长的 会自动去重 不是连续分布 不能用索引坐标访问
统计用户IP,IP投票;还能够作交叉并补的集合
HashSet<int> hashSet=new HashSet<int>();
hashSet.AddFirst(1);
hashSet.AddFirst(1);
hashSet.AddFirst(2);
hashSet.AddFirst(3);
hashSet.AddLast(10);
HashSet<int> hashSet1=new HashSet<int>();
hashSet1.AddFirst(1);
hashSet1.AddFirst(2);
hashSet1.AddLast(3);
hashSet1.AddLast(7);
hashSet1.IntersectWith(hashSet);//交集 一、二、3
hashSet1.UnionWith(hashSet);//并集一、二、三、七、10
hashSet1.ExceptWith(hashSet);//差集 10
hashSet1.SymmetricExceptWith(hashSet);//补集 7
*交叉并补只能执行一次*
SortedSet:排序的集合,能够去重加排序;也能够作交叉并补
SortSet<int> sortSet=new SortSet<int>();
sortSet.AddFirst(1);
sortSet.AddFirst(1);
sortSet.AddFirst(2);
sortSet.AddFirst(3);
sortSet.AddLast(10);
Key-Value
HashTable:key—value 体积能够动态增长 拿着key计算一个地址,而后放入key-value
object-装箱拆箱 若是是不一样的key获得相同的地址,第二个在前面地址上+1
查找的时候,若是地址对应的数据key不对,那就+1查找。。
浪费了空间 基于数组实现
查找数据 一次定位 增删 一次定位;增删改查 都很快
浪费空间,数据太多 重复定位 效率就下去了
HashTable table=new HashTable();
table.Add("1","0001");
table.Add("2","0004");
table["3"]="0003";
线程安全
Hashtable.Synchronized(table);//只有一个线程写 多个线程读
Dictionary:泛型 key-value 读写增删改查都很快 有序的
Dictionary<int,string> dic=new Dictionary<int,string> ();
dic[1]="1";
SortedDictionary:泛型 key-value 读写增删改查都很快 有序的
SortedDictionary<int,string> dic=new SortedDictionary<int,string> ();
dic[1]="1";
SortedList:泛型 key-value 读写增删改查都很快 有序的 按照key排序
SortDictionary<int,string> dic=new SortDictionary<int,string> ();
dic[1]="1";
ILIst、IQueryable、IEnumerable、ICollection
接口是标识功能的,不一样的接口拆开,为了接口隔离,尽管有重复
IList 能够下标访问
IEnumerable 遍历才会查询比较 迭代器yield 任何数据集合 都实现了不一样的数据结构,提供了统一的访问接口 yield访问模式
IQueryable 表达式目录树解析 延迟到遍历的时候才会去执行