c#之字典
来源:互联网 发布:我国生态数据 编辑:程序博客网 时间:2024/06/03 18:39
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 字典{ public class AA { public Dictionary<int, string> _dictionary = new Dictionary<int, string>(); //字典,键值对,键是唯一的,值不需要唯一 public void add() { _dictionary.Add(50,"likang"); //往字典里添加元素 _dictionary.Add(90,"king"); _dictionary.Add(70,"德邦"); } public void Method() { // Console.WriteLine("对于key=50而言,value={0}",_dictionary.Count);//_dictionary.Count 获取字典中键值对的数目; Console.WriteLine(_dictionary[50]); } } class Program { static void Main(string[] args) { AA aa = new AA(); aa.add(); aa._dictionary.Add(60,"likang"); //键是唯一的,值却不是,就是说一个键只能对应一个值,而同一个值却可以对应对个key; aa._dictionary[50] = "LIKANG"; //更改值 foreach (int item in aa._dictionary.Keys) //_dictionary.Values 所有字典的值的集合 _dictionary.Keys 所有字典的key的集合 { //Console.WriteLine(item); } aa._dictionary.Remove(50); //移除字典中的某一元素 // aa._dictionary.Clear(); //清楚字典中所有元素; //遍历字典 foreach (KeyValuePair<int,string> item in aa._dictionary) { Console.WriteLine("key是{0},值是{1}",item.Key,item.Value); } // aa.Method(); if (aa._dictionary.ContainsValue("likang")) //_dictionary.ContainsValue 判断该字典中是否包含对应的值 { //_dictionary.ContainsKey 判读单该字典中是否包含对应的key; Console.WriteLine(55); } Console.Read(); } }}
阅读全文
0 0
- c#之字典
- C#基础知识之使用字典
- c#之字典学习笔记
- c#字典
- C#字典
- C# 开发字典
- C#类库字典
- C# Dictionary 字典
- C#的字典类
- C# Dictionary 字典
- C#字典使用
- C#的Dictionary字典
- C#使用资源字典
- C# 字典 Dictionary 遍历
- 网站c#字典排序
- C# Dictionary 字典简介
- C#学习日记 字典
- C# Dictionary 字典
- JAVA正则表达式:Pattern类与Matcher类详解(转)
- Java 反射
- transwarp Slipstream 简介之实战应用
- ionic侧栏菜单案例
- 从wireshark中获取H264码流详解
- c#之字典
- freeradius负载均衡
- 关于整合Nginx+Tomcat搭建高性能负载均衡服务体系
- mySql函数总结
- arm linux 控制台shell退出不能重启
- 21.springboot创建含有异步方法的service
- 快速定位磁盘满的位置
- spring Boot
- 使用git版本管理工具上传代码到码云