Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在c#linq中使用一个元素(值)查找键_C#_Linq_Dictionary - Fatal编程技术网

如何在c#linq中使用一个元素(值)查找键

如何在c#linq中使用一个元素(值)查找键,c#,linq,dictionary,C#,Linq,Dictionary,我有下一本c语言词典# Dictionary Dictionary=newdictionary(); {1,1,2,3,4 2, 4,5,6,7 3,1} 我想找到列表中只有一个元素的元素(字典中的最后一个)。 我该怎么做?编辑: 我刚意识到你想找到钥匙 List<int> result = dictionary.Where(x => x.Value.Count == 1).Select(x => x.Key).ToList(); List result=dictio

我有下一本c语言词典#

Dictionary Dictionary=newdictionary();
{1,1,2,3,4 2, 4,5,6,7 3,1}

我想找到列表中只有一个元素的元素(字典中的最后一个)。 我该怎么做?

编辑:

我刚意识到你想找到钥匙

List<int> result = dictionary.Where(x => x.Value.Count == 1).Select(x => x.Key).ToList();
List result=dictionary.Where(x=>x.Value.Count==1);
这应该就是你要找的那个

原件:

我相信您正在使用LINQ寻找此类产品:

IEnumerable<List<int>> result = dictionary.Values.Where(x => x.Count == 1);
IEnumerable结果=dictionary.Values.Where(x=>x.Count==1);

如果你想把它放在列表中,我会考虑枚举集合。

List<List<int>> result = dictionary.Values.Where(x => x.Count == 1).ToList();
List result=dictionary.Values.Where(x=>x.Count==1.ToList();
希望这能回答您的问题。

这样:

Dictionary<int, List<int>> dictionary = new Dictionary<int, List<int>>();

List<KeyValuePair<int, List<int>>> result = dictionary.Where(keyValuePair => keyValuePair.Value.Count == 1).ToList();
Dictionary Dictionary=newdictionary();
列表结果=dictionary.Where(keyValuePair=>keyValuePair.Value.Count==1.ToList();
发生了什么事

dictionary.Where
|在
dictionary
中搜索

keyValuePair=>
|一个
keyValuePair
我将用名称
keyValuePair

keyValuePair.Value
|哪个有它的值(它是一个
列表

keyValuePair.Value.Count==1
|且
Count
等于
1


.ToList()
|然后返回一个包含匹配的
键值对的列表

是否需要频繁查找这些元素?还是在一个大的时间跨度内只有一次?
Dictionary<int, List<int>> dictionary = new Dictionary<int, List<int>>();

List<KeyValuePair<int, List<int>>> result = dictionary.Where(keyValuePair => keyValuePair.Value.Count == 1).ToList();