说我有这本词典:
ConcurrentDictionary<string, Location> connections;
我想从这个字典中获取一个与其值相匹配的键的列表。例如,这对我有用:
List<string> users = connections.Where(x.Value.IsNearby(anotherLocation)).ToDictionary(x => x.Key, x => x.Value).Keys.ToList();
但这很讨厌,因为它从字典到子字典,再到键列表。有更优雅的方式吗?
答案 0 :(得分:2)
不清楚为什么你完全接到ToDictionary
电话。您只需要Select
来电:
List<string> users = connections.Where(x => x.Value.IsNearby(anotherLocation)
.Select(x => x.Key)
.ToList();