舰队collection路基:C# Dictionary 终极使用方法
来源:百度文库 编辑:九乡新闻网 时间:2024/05/13 18:26:17
- using System;
- using System.Collections.Generic;
- class DictionaryDemo
- {
- static void Main(string[] args)
- {
- DictionaryDemo001();
- Console.ReadLine();
- DictionaryDemo002();
- Console.ReadLine();
- DictionaryDemo003();
- Console.ReadLine();
- }
- ///
- /// 一般用法
- ///
- static void DictionaryDemo001()
- {
- Dictionary
dict = new Dictionary (); - dict.Add(1, "111");
- dict.Add(2, "222");
- //判断是否存在相应的key并显示
- if (dict.ContainsKey(2))
- {
- Console.WriteLine(dict[2]);
- }
- //遍历Keys
- foreach (var item in dict.Keys)
- {
- Console.WriteLine("Key:{0}", item);
- }
- //遍历Values
- foreach (var item in dict.Values)
- {
- Console.WriteLine("value:{0}", item);
- }
- //遍历整个字典
- foreach (var item in dict)
- {
- Console.WriteLine("key:{0} value:{1}", item.Key, item.Value);
- }
- }
- ///
- /// 参数为其它类型
- ///
- static void DictionaryDemo002()
- {
- Dictionary
dict = new Dictionary (); - dict.Add("1", "1,11,111".Split(','));
- dict.Add("2", "2,22,222".Split(','));
- Console.WriteLine(dict["2"][2]);
- }
- ///
- /// 调用自定义类
- ///
- static void DictionaryDemo003()
- {
- Dictionary
dict = new Dictionary (); - for (int i = 0; i < 10; i++)
- {
- yongfa365 y = new yongfa365();
- y.UserCode = i;
- y.UserName = "www.yongfa365.com " + i.ToString();
- dict.Add(i, y);
- }
- foreach (var item in dict)
- {
- Console.WriteLine("{0} One:{1} UserName:{2}", item.Key, item.Value.UserCode, item.Value.UserName);
- }
- }
- }
- class yongfa365
- {
- public int UserCode { get; set; }
- public string UserName { get; set; }
- }
C# Dictionary 终极使用方法
C# Dictionary 用法
Dictionary*
C#资源文件的使用方法
oracle Dictionary cache
使用方法
关于c#
数据结构-C#
Lover·Loving Dictionary《爱·动听之抒情篇》
DataContractJsonSerializer反序列化Dictionary - Lullaby's Blog - CSDN博客
用C#播放mp3[C#实例]
c#线程相关概念
c++与c#区别
C#事件(event)解析
C#数组操作
C#程序书写规范
C#教程:线程同步
C#网络编程入门
C#中几种换行符
C#中 dataGridView用法
C#数组定义例子
C# 读写Config文件
c# 时间格式
如何学.net C# ?