Assuming you have an initial dictionary (matching keys with values), you can use some Linq to convert it to an inverse dictionary without manually creating this inverse dictionary.
var newDict = initialDict.Select(x=>x.Value).Distinct().ToDictionary(x=>x, x=> initialDict.Where(kvp=>kvp.Value == x).Select(kvp=>kvp.Key));
Select the highlighted originalValues from the source dictionary and use them as newKeys . Your newValues is the set of your originalKeys that appears on each originalValue / newKey .
Example: https://dotnetfiddle.net/dhwUSC
Given the source dictionary
var initialDict = new Dictionary<int, string>{ {1, "Value"}, {2, "Value"}, {3, "Value"}, {4, "Value"}, {5, "Value2"} };
the above function returns
Value: {1, 2, 3, 4} Value2: {5}
source share