110,536
社区成员
发帖
与我相关
我的任务
分享
Dictionary<int, int> abc = new Dictionary<int, int>();
abc.Add(1, 3);
abc.Add(2, 2);
abc.Add(3, 3);
abc.Add(4, 1);
abc.Add(5, 3);
abc.Add(6, 4);
System.Collections.Hashtable hst1 = new System.Collections.Hashtable();
System.Collections.Hashtable hst2 = new System.Collections.Hashtable();
foreach (var item in abc)
{
if (!hst1.ContainsValue(item.Value))
{
hst1.Add(item.Key, item.Value);
}
else
{
if (!hst2.ContainsValue(item.Value))
hst2.Add(item.Key, item.Value);
}
}
foreach (var item in abc)
{
foreach (System.Collections.DictionaryEntry de in hst2)
{
if (item.Value == (int)de.Value)
{
System.Windows.Forms.MessageBox.Show(item.Key.ToString() + " " + item.Value.ToString());
}
}
}
Dictionary<int, int> abc = new Dictionary<int, int>();
abc.Add(1, 3);
abc.Add(2, 2);
abc.Add(3, 3);
abc.Add(4, 1);
abc.Add(5, 3);
abc.Add(6, 4);
var result = abc.GroupBy(a => a.Value).Where(g => g.Count(kv => kv.Value == g.Key) > 1).SelectMany(g => g);
foreach (var kv in result)
{
Console.WriteLine(string.Format("[{0},{1}]", kv.Key, kv.Value));
}
结果[1,3]
[3,3]
[5,3]