驾驶证样式改革:C#中泛型之Dictionary
来源:百度文库 编辑:中财网 时间:2024/05/17 00:12:53
1、命名空间:
(程序集:mscorlib)
2、描述:
1)、从一组键(Key)到一组值(Value)的映射,每一个添加项都是由一个值及其相关连的键组成
2)、任何键都必须是唯一的
3)、键不能为空引用null(VB中的Nothing),若值为引用类型,则可以为空值
4)、Key和Value可以是任何类型(string,int,custom class 等)
3、创建及初始化:
Dictionary myDictionary = new Dictionary() ;
4、添加元素:
myDictionary.Add("C#",0);
myDictionary.Add("C++",1);
myDictionary.Add("C",2);
myDictionary.Add("VB",2);
5、查找元素By Key:
if(myDictionary.ContainsKey("C#"))
{
Console.WriteLine("Key:{0},Value:{1}", "C#", myDictionary["C#"]);
}
6.遍历元素 By KeyValuePair
foreach (KeyValuePair kvp in myDictionary)
{
Console.WriteLine("Key = {0}, Value = {1}",kvp.Key, kvp.Value);
}
7、仅遍历键 By Keys 属性:
Dictionary.KeyCollection keyCol = myDictionary.Keys;
foreach (string key in keyCol/*string key in myDictionary.Keys*/)
{
Console.WriteLine("Key = {0}", key);
}
8、仅遍历值By Valus属性:
Dictionary.ValueCollection valueCol = myDictionary.Values;
foreach (int value in valueCol)
{
Console.WriteLine("Value = {0}", value);
}
9.移除指定的键值By Remove方法:
myDictionary.Remove("C#");
if (myDictionary.ContainsKey("C#"))
{
Console.WriteLine("Key:{0},Value:{1}", "C#", myDictionary["C#"]);
}
else
{
Console.WriteLine("不存在 Key : C#");
(程序集:mscorlib)
2、描述:
1)、从一组键(Key)到一组值(Value)的映射,每一个添加项都是由一个值及其相关连的键组成
2)、任何键都必须是唯一的
3)、键不能为空引用null(VB中的Nothing),若值为引用类型,则可以为空值
4)、Key和Value可以是任何类型(string,int,custom class 等)
3、创建及初始化:
4、添加元素:
myDictionary.Add("C#",0);
myDictionary.Add("C++",1);
myDictionary.Add("C",2);
myDictionary.Add("VB",2);
5、查找元素By Key:
if(myDictionary.ContainsKey("C#"))
{
Console.WriteLine("Key:{0},Value:{1}", "C#", myDictionary["C#"]);
}
6.遍历元素 By KeyValuePair
foreach (KeyValuePair
{
Console.WriteLine("Key = {0}, Value = {1}",kvp.Key, kvp.Value);
}
7、仅遍历键 By Keys 属性:
Dictionary
foreach (string key in keyCol/*string key in myDictionary.Keys*/)
{
Console.WriteLine("Key = {0}", key);
}
8、仅遍历值By Valus属性:
Dictionary
foreach (int value in valueCol)
{
Console.WriteLine("Value = {0}", value);
}
9.移除指定的键值By Remove方法:
myDictionary.Remove("C#");
if (myDictionary.ContainsKey("C#"))
{
Console.WriteLine("Key:{0},Value:{1}", "C#", myDictionary["C#"]);
}
else
{
Console.WriteLine("不存在 Key : C#");
C#之Windows Service相关
C#数据报编程之单播
longman 双解dictionary下载
dictionary不记得是什么??
learners' dictionary 和dilingual dictionary有什么区别呀?
Longman Dictionary of Contemporary English
字典情人 The Sleeping Dictionary
求webster dictionary下载地址!!
求洪恩-『编程之道—C#程序设计入门 』下载地址
求洪恩编程之道系列C#程序入门下载地址(BT除外)
Each of them has a dictionary.
How much did you () for the dictionary
Merriam-Webster's Collegiate Dictionary 哪有卖?
lexicon和dictionary有什么区别
dictionary.com 有没有简体中文版的网页?
New Edition of Oxford Concise Dictionary (1976)
Cambridge Advanced Learner\'s Dictionary
Longman.Dictionary.of.Contemporary.English. 2005
Longman.Dictionary.of.Contemporary.English 2005
vbscript中dictionary对象的用法
Longman Dictionary of Contemporary English安装
It is Lucy's dictionary.
A dictionary is an useful book.找错
random house webster's college dictionary