C#数组 List、Dictionary 、Arrary、ArrayList
#region Dictionary 泛型集合,动态修改查询、查询和排序
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("北京", "1");
dic.Add("山西", "2");
dic.Add("深圳", "3"); if (!dic.ContainsKey("山西"))
{
dic.Add("山西", "5");
}
foreach (KeyValuePair<string, string> item in dic)
{
Console.WriteLine("Key:{0},Value{1}", item.Key, item.Value);
}
//排序遍历
var result = from d in dic orderby d.Key select d;
foreach (KeyValuePair<string, string> item in result)
{
Console.WriteLine("Key:{0},Value{1}", item.Key, item.Value);
}
#endregion
Arrary:
#region Arrary 创建固定长度的数组
string[] str = { "1", "2", "3" };
int[] i = { 1, 2, 3, 4 };
//取数
string[] arr = new string[3];
arr[0] = "山西";
arr[1] = "广州";
arr[2] = "上海";
Console.WriteLine("{0}",arr.Length);
#endregion
ArrayList:
#region ArrayList 允许动态增加,移除元素,排序、反转数组 using System.Collections;
ArrayList arraylist = new ArrayList();
arraylist.Add("山西");
arraylist.Add("北京");
Console.WriteLine("长度{0}",arraylist.Count);
arraylist.Remove("北京");
arraylist.RemoveAt(1);
//反转
arraylist.Reverse();
//排序
arraylist.Sort();
foreach (string s in arraylist)
{
Console.WriteLine(s);
}
//允许创建元素为类实例的泛型数组
ArrayList arrList = new ArrayList();
arrList.Add(new Person(1, "1"));
foreach (Person item in arrList)
{
Console.WriteLine("item.Id:{0},item.Name:{1}",item.ID,item.Name);
}
#endregion
List:
#region List 创建泛型集合,动态增加、排序、反转 using System.Collections.Generic;
List<Person> lists = new List<Person>();
lists.Add(new Person(1, "2"));
foreach (Person item in lists)
{
Console.WriteLine("item.Id:{0},item.Name:{1}", item.ID, item.Name);
}
#endregion
C#数组 List、Dictionary 、Arrary、ArrayList的更多相关文章
- C#中数组、集合(ArrayList)、泛型集合List<T>、字典(dictionary<TKey,TValue>)全面对比
C#中数组.集合(ArrayList).泛型集合List<T>.字典(dictionary<TKey,TValue>)全面对比 为什么把这4个东西放在一起来说,因为c#中的这4 ...
- C#数组,List,Dictionary的相互转换
本篇文章会向大家实例讲述以下内容: 将数组转换为List 将List转换为数组 将数组转换为Dictionary 将Dictionary 转换为数组 将List转换为Dictionary 将Dicti ...
- 数组、List和ArrayList的区别
有些知识点可能平时一直在使用,不过实际开发中我们可能只是知其然不知其所以然,所以经常的总结会对我们的提高和进步有很大的帮助,这里记录自己在工作之余的问题,持续更新,欢迎高手斧正. 数组.List和Ar ...
- C#重的数组、集合(ArrayList)、泛型集合(list<T>)三者比较及扩展延伸……
本来我只想总结下数组.集合(ArrayList).泛型集合(list<T>)三者的比较的,可以一写下来要扩展的知识点有点多了,只能写一个小的知识点列表了如下: 1.数组.集合(ArrayL ...
- JAVA 基本数据结构--数组、链表、ArrayList、Linkedlist、hashmap、hashtab等
概要 线性表是一种线性结构,它是具有相同类型的n(n≥0)个数据元素组成的有限序列.本章先介绍线性表的几个基本组成部分:数组.单向链表.双向链表:随后给出双向链表的C.C++和Java三种语言的实现. ...
- C#数组,List,Dictionary,IQueryable,IEnumerable的相互转换
本篇文章会向大家实例讲述以下内容: 将数组转换为List 将List转换为数组 将数组转换为Dictionary 将Dictionary 转换为数组 将List转换为Dictionary 将Dicti ...
- 一个Json、数组、Dictionary转换和数组对比的C#实例
最近做了一个程序,里面一段代码用到Json.数组.Dictionary转换和数组对比的一些知识,虽然在实际碰到类似问题时候有更好的方法,但这就当是一次基础知识的回顾,现在分享一下. 先介绍下要实现的业 ...
- Collection集合重难点梳理,增强for注意事项和三种遍历的应用场景,栈和队列特点,数组和链表特点,ArrayList源码解析, LinkedList-源码解析
重难点梳理 使用到的新单词: 1.collection[kəˈlekʃn] 聚集 2.empty[ˈempti] 空的 3.clear[klɪə(r)] 清除 4.iterator 迭代器 学习目标: ...
- Hastable和Dictionary以及ArrayList和(List,LinkedList,数组)的区别
Hastable和Dictionary的区别:(键值对) 1:单线程程序中推荐使用 Dictionary, 有泛型优势, 且读取速度较快, 容量利用更充分. 2:多线程程序中推荐使用 Hashtabl ...
- C#中Dictionary、ArrayList、Hashtable和Array的区别
IDictionary接口是所有字典类集合的基本接口,该接口与ICollection,IEnumerable接口是所有非泛型类集合的最基本的接口 IEnumerable接口用于公开枚举数,该枚举数支持 ...
随机推荐
- 【设计模式】—— 适配器模式Adapter
前言:[模式总览]——————————by xingoo 模式意图 如果已经有了一种类,而需要调用的接口却并不能通过这个类实现.因此,把这个现有的类,经过适配,转换成支持接口的类. 换句话说,就是把一 ...
- Centos中安装和配置vsftp简明教程
一.vsftp安装篇 # 安装vsftpd yum -y install vsftpd # 启动 service vsftpd start # 开启启动 chkconfig vsftpd on 二.v ...
- 题解 P5239 【回忆京都】
你们这些写题解的,就不能把话说清楚嘛!(吐槽1) 你们这些出题的,就不能多出点东方嘛!(吐槽2) 你们这些做题的,就不来写一篇详细一点的题解嘛!(吐槽3) 以上均是个人吐槽,纯属吐槽,不带任何针对性和 ...
- 【bzoj3091】 城市旅行
http://www.lydsy.com/JudgeOnline/problem.php?id=3091 (题目链接) 题意 给出一棵无根树,维护四个操作.link,cut,路径加法,路径期望查询. ...
- root和alias的区别
先来看看官方说明: root 的用法: location /request_path/image/ { root /local_path/; } 当客户端请求 /request_path/image/ ...
- SpringBoot中使用SpringDataJPA
SpringDataJPA的使用 JPA是什么? JPA(Java Persistence API)是Sun官方提出的Java持久化规范. 为Java开发人员提供了一种对象/关联映射工具来管理Java ...
- redis 中用正则找key
获取 redis 中所有的 key 可用使用 *. redis 127.0.0.1:6379> KEYS * 1) "w3c3" 2) "w3c1" 3) ...
- 生成ssh-key for GIthub
在Github里,如果我们想通过ssh的方式进行身份验证,我们就需要建立ssh-key: 方法一: git GUI,点击help,选择Generate ssh key
- Nested Loops(嵌套循环)
先扫描驱动表的(外表),外表的每一行驱动内表,然后匹配,所以nest loops不是主要依赖于内表有多少行,而是非常依赖于驱动表到底有多少行参与nested loops,因为驱动表(或者准确的说是驱动 ...
- 数据结构(三)串---KMP模式匹配算法实现及优化
KMP算法实现 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include ...