不同的价值观在字典< TKEY的,TValue>字典、价值观、不同、LT

由网友(悟空很调皮)分享简介:我想遍历不同的价值观在一个字典列表:所以,我有键值对的字典。我如何得到一串钥匙,只是不同的值从字典列表?解决方案 VAR distinctList = mydict.Values​​.Distinct()了ToList()。另外,你不需要调用了ToList():的foreach(在mydict.Values​​....

我想遍历不同的价值观在一个字典列表:

所以,我有键值对的字典。

我如何得到一串钥匙,只是不同的值从字典列表?

解决方案

  VAR distinctList = mydict.Values​​.Distinct()了ToList()。
 

另外,你不需要调用了ToList():

 的foreach(在mydict.Values​​.Distinct VAR值())
{
  //处理。
}
 

编辑:我误解你的问题,我想您从词典中想不同的值。上述code提供的。

键是自动截然不同。因此,只要使用

 的foreach(在mydict.Keys VAR键)
{
  //处理它
}
 
新中国70年影像辞典,这本 百科全书 值得收藏

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
}

阅读全文

相关推荐

最新文章