当前位置: 首页 > news >正文

政府网站的做上海百度seo公司

政府网站的做,上海百度seo公司,鄂州吧,郑州商城网站开发字典 字典是C#中的一种集合&#xff0c;它存储键值对&#xff0c;并且每个键与一个值相关联。 创建字典 Dictionary<键的类型, 值的类型> 字典名字 new Dictionary<键的类型, 值的类型>(); Dictionary<int, string> dicStudent new Dictionary<int, str…

字典

字典是C#中的一种集合,它存储键值对,并且每个键与一个值相关联。

创建字典

Dictionary<键的类型, 值的类型> 字典名字 = new Dictionary<键的类型, 值的类型>();

Dictionary<int, string> dicStudent = new Dictionary<int, string>();

字典基本操作

添加元素

            dicStudent.Add(2, "张三");dicStudent.Add(5, "李四");dicStudent.Add(8, "王五");

访问元素

字典名[键名];

Console.WriteLine(dicStudent[5]);

检查键是否存在

            if (dicStudent.ContainsKey(1)){Console.WriteLine("键存在");}else{Console.WriteLine("键不存在");}if (dicStudent.ContainsKey(2)){Console.WriteLine("键存在");}else{Console.WriteLine("键不存在");}

字典容量

            int count = dicStudent.Count;Console.WriteLine(count);

遍历字典

            foreach (KeyValuePair<int, string> item in dicStudent){Console.WriteLine($"{item.Key}:{item.Value}");}

为了简化字典遍历的写法使用 var 代替 KeyValuePair<int, string> 类型。

            foreach (var item in dicStudent){Console.WriteLine($"{item.Key}:{item.Value}");}

删除元素

            dicStudent.Remove(5);         //移除5键这个键值对foreach (var item in dicStudent){Console.WriteLine($"{item.Key}:{item.Value}");}

获取键的列表

            var keys = dicStudent.Keys;foreach (var key in keys){Console.WriteLine(key);}

获取值的列表

            var values = dicStudent.Values;foreach (var value in values){Console.WriteLine(value);}

清空字典

            dicStudent.Clear();
http://www.hrbkazy.com/news/16211.html

相关文章:

  • 用 asp net 做 的网站深圳百度关键
  • 照片分享网站模板下载简述网站推广的方式
  • git怎么做隐私政策网站seo点击软件排名优化
  • 建筑方案设计收费标准seo网站排名后退
  • 南宁大型网站推广公司百度一下百度一下百度一下
  • 用cdr做网站设计尺寸要多少西安今天刚刚发生的新闻
  • 做律师百度推广的网站如何做网站seo排名优化
  • 公司网站开发排名seo标题优化关键词
  • 济南公司做网站的价格网站制作的基本流程
  • 网站日志分析之后咋做杭州推广公司
  • 公司网站开发费计入办公费长春网站建设方案报价
  • 草桥做网站的公司企业网站免费制作
  • 网站建设直播网站推广方法
  • wordpress网页移动北京seo网站优化培训
  • 网页制作免费网站洛阳市网站建设
  • 哈尔滨网站建设公司名字重庆白云seo整站优化
  • 专门做酒店设计的网站广州网络营销运营
  • 备案号怎么放置到网站网站设计公司报价
  • 一般通过少女杭州seo中心
  • 做外贸的网站域名怎么买网络推广的公司更可靠
  • 公司网站建设基本流程哈尔滨百度推广联系人
  • 做网站需要的导航我想做个网站怎么做
  • 做网站公司深圳站长工具永久
  • php 茶叶网站源码时代培训机构官网
  • 怎样做关于自己的网站最好的免费建站网站
  • 网站的技术解决方案制作网页完整步骤代码
  • 旅游网站建设杭州seo整站优化
  • 做多语言网站教程竞价网站
  • 办公空间设计网站崇左seo
  • 一家专做节日商品的网站windows优化大师破解版