foreach (int i in d.Values) Console.Write(i);
2016-07-27 12:09
447 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication8
{
class Program
{
static void Main(string[] args)
{
Dictionary<string, int> d = new Dictionary<string, int>();
d.Add("One", 1);
d["Two"] = 2; // adds to dictionary because "two" is not already present
d["Two"] = 22; // updates dictionary because "two" is now present
d["Three"] = 3;
Console.WriteLine(d["Two"]); // Prints "22"
Console.WriteLine(d.ContainsKey("One")); // true (fast operation)
Console.WriteLine(d.ContainsValue(3)); // true (slow operation)
// Three different ways to enumerate the dictionary:
foreach (KeyValuePair<string, int> kv in d) // One ; 1
Console.WriteLine(kv.Key + "; " + kv.Value); // Two ; 22
// Three ; 3
foreach (string s in d.Keys) Console.Write(s); // OneTwoThree
Console.WriteLine();
foreach (int i in d.Values) Console.Write(i); // 1223
}
}
}
/*
22
True
True
One; 1
Two; 22
Three; 3
OneTwoThree
1223请按任意键继续. . .
*/
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication8
{
class Program
{
static void Main(string[] args)
{
Dictionary<string, int> d = new Dictionary<string, int>();
d.Add("One", 1);
d["Two"] = 2; // adds to dictionary because "two" is not already present
d["Two"] = 22; // updates dictionary because "two" is now present
d["Three"] = 3;
Console.WriteLine(d["Two"]); // Prints "22"
Console.WriteLine(d.ContainsKey("One")); // true (fast operation)
Console.WriteLine(d.ContainsValue(3)); // true (slow operation)
// Three different ways to enumerate the dictionary:
foreach (KeyValuePair<string, int> kv in d) // One ; 1
Console.WriteLine(kv.Key + "; " + kv.Value); // Two ; 22
// Three ; 3
foreach (string s in d.Keys) Console.Write(s); // OneTwoThree
Console.WriteLine();
foreach (int i in d.Values) Console.Write(i); // 1223
}
}
}
/*
22
True
True
One; 1
Two; 22
Three; 3
OneTwoThree
1223请按任意键继续. . .
*/
相关文章推荐
- Umbraco中的ModelBuilder
- Runtime实例之-UIMenuController的使用
- PowerBuilder中按键处理使用的键盘码
- UITableView的其他设置
- iOS UICollectionViewCell拖拽移动(配Demo下载)
- luigi学习5-task详解
- mybatis result maps collection already contains value
- easyUI——控制datagrid的显示与隐藏
- EasyUI - 修改datagrid的content-type
- AS中build.gradle文件配置讲解
- 文件包含漏洞
- EasyUI——numberspinner的onChange事件
- iOS UI控件之----UIButton
- [LeetCode] 60. Permutation Sequence
- xib或者SB中设置边框颜色
- GSS4 - Can you answer these queries IV(线段树懒操作)
- UGUI学习的第一天
- SPOJ GSS1_Can you answer these queries I(线段树区间合并)
- iOS开发从入门到精通--UIGesture手势,图片的缩放和旋转
- Count Numbers with Unique Digits java解法