不同的价值观在字典&LT; TKEY的,TValue&GT; [英] Distinct Values in Dictionary<TKey,TValue>
本文介绍了不同的价值观在字典&LT; TKEY的,TValue&GT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想遍历不同的价值观在一个字典列表:
所以,我有键值对的字典。
我如何得到一串钥匙,只是不同的值从字典列表?
解决方案
VAR distinctList = mydict.Values.Distinct()了ToList()。
另外,你不需要调用了ToList():
的foreach(在mydict.Values.Distinct VAR值())
{
//处理。
}
编辑:我误解你的问题,我想您从词典中想不同的值。上述code提供的。
键是自动截然不同。因此,只要使用
的foreach(在mydict.Keys VAR键)
{
//处理它
}
I'm trying to loop over distinct values over a dictionary list:
So I have a dictionary of key value pairs .
How do I get just the distinct values of string keys from the dictionary list?
解决方案
var distinctList = mydict.Values.Distinct().ToList();
Alternatively, you don't need to call ToList():
foreach(var value in mydict.Values.Distinct())
{
// deal with it.
}
Edit: I misread your question and thought you wanted distinct values from the dictionary. The above code provides that.
Keys are automatically distinct. So just use
foreach(var key in mydict.Keys)
{
// deal with it
}
这篇关于不同的价值观在字典&LT; TKEY的,TValue&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文