It depends.
If you have an ever changing dictionary and need to get that information only once, use this:
MyDict.GroupBy(x => x.Value).Where(x => x.Count() > 1)
However, if you have a dictionary that is more or less static and need to get this information more than once, you should not just save your data in a Dictionary but also in a ILookup
with the value of the dictionary as the key and the key of the dictionary as the value:
var lookup = MyDict.ToLookup(x => x.Value, x => x.Key).Where(x => x.Count() > 1);
To print the info, you can use the following code:
foreach(var item in lookup)
{
var keys = item.Aggregate("", (s, v) => s+", "+v);
var message = "The following keys have the value " + item.Key + ":" + keys;
Console.WriteLine(message);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…