Dictionary的简单问题,送分拉! Dictionary<string, int> dic = new Dictionary<string, int>();dic.add("香蕉",1);我现在知道如何通过"香蕉"来获取1 --->dic[香蕉]根据1,如何取得"香蕉"? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 foreach (string s in dic.Keys) if (dic[s] == 1) Console.WriteLine(s); foreach (string key in dic.Keys) { if (dic[key] == 1) MessageBox.Show(key); // 值为1的key可能有多个. } 楼上搞错了Dictionary <TKeys, TValues>"香蕉"是键 建议lz有空好好看看数据结构方面的书,看看Dictionary到底用来做什么。 好像不行吧,dic.add("香蕉",1); "香蕉"是KEY吧,你也可以添加两个1,比如:dic.add("香蕉",1); dic.add("苹果",1); 如果你根据1来取,结果是"香蕉"还是"苹果"? foreach(object obj in 集合的名字.values) { foreach(object obj1 int 集合的名字.keys) { if(集合[obj1]==obj) { 得到了 } } } static void Main(string[] args){ string[] strName = { "中国", "武汉", "北京", "南宁", "武汉", "广州", "北京", "西藏", "武汉" }; Dictionary<string, int> dic = new Dictionary<string, int>(); foreach (string s in strName) { if (dic.ContainsKey(s)) dic[s]++; else dic[s] = 1; } //在此继续写代码,返回字符串中出现最多字符(此注释上面不允许写)} static void Main(string[] args) { string[] strName = { "中国", "武汉", "北京", "南宁", "武汉", "广州", "北京", "西藏", "武汉" }; Dictionary<string, int> dic = new Dictionary<string, int>(); foreach (string s in strName) { if (dic.ContainsKey(s)) dic[s]++; else dic[s] = 1; } int max = 0; string name = ""; foreach (string s in dic.Keys) if (dic[s] > max) { max = dic[s]; name = s; } Console.WriteLine("{0}出现次数最多,出现了{1}次", name, max); } 将文件夹中的图片动态显示在页面上 准备做一个内容沟通用的类似msn工具,功能实现上没有问题,但在表现形式上机要求漂亮一点,有什么组件可以用的吗? 如何使用C#取得VSS目录 谁能给一个局域网传送文件的例子? 怎么取得窗体中所包含的所有控件名字? 文件读写的问题,菜鸟求教大侠们 有关C#内存问题 急!窗体之间传值? 如何通过代码调整button2的位置,请大家帮忙.我用 button2.location.x=150始终不行,应该如何! C# 多个自定义控件 怎么互不影响 请问VSS6.0C在哪儿下载?谢谢 窗体关闭问题?
foreach (string s in dic.Keys)
if (dic[s] == 1)
Console.WriteLine(s);
{
if (dic[key] == 1)
MessageBox.Show(key); // 值为1的key可能有多个.
}
dic.add("香蕉",1);
"香蕉"是KEY吧,
你也可以添加两个1,比如:
dic.add("香蕉",1);
dic.add("苹果",1);
如果你根据1来取,结果是"香蕉"还是"苹果"?
{
foreach(object obj1 int 集合的名字.keys)
{
if(集合[obj1]==obj)
{
得到了
}
}
}
static void Main(string[] args)
{
string[] strName = { "中国", "武汉", "北京", "南宁", "武汉", "广州", "北京", "西藏", "武汉" }; Dictionary<string, int> dic = new Dictionary<string, int>();
foreach (string s in strName)
{
if (dic.ContainsKey(s))
dic[s]++;
else
dic[s] = 1;
} //在此继续写代码,返回字符串中出现最多字符(此注释上面不允许写)}
static void Main(string[] args)
{
string[] strName = { "中国", "武汉", "北京", "南宁", "武汉", "广州", "北京", "西藏", "武汉" }; Dictionary<string, int> dic = new Dictionary<string, int>();
foreach (string s in strName)
{
if (dic.ContainsKey(s))
dic[s]++;
else
dic[s] = 1;
} int max = 0;
string name = "";
foreach (string s in dic.Keys)
if (dic[s] > max)
{
max = dic[s];
name = s;
}
Console.WriteLine("{0}出现次数最多,出现了{1}次", name, max);
}