Please carry me if you think that I have not done enough research before asking
Problem Just came across a business requirement in which we need to make sure that the values ββin the dictionary are unique. those. we must filter the dictionary, and the result of such a filter should have pairs of key values ββwith unique values.
By the way, this is a simple Dictionary with string values ββand string keys. To clarify in more detail, below are the sample values and the expected output values ββ-
sourceDictionary will have the meanings shown below (only for the presentation of data, not syntactically correct) - {{"Item1", "Item One"}, {"Item11", "Item One"}, {"Item2", "Second item "}, {" Item22 "," Item Two "}} for this input, filterDictionary should look like this: {{" Item1 "," Item One "}, {" Item2 "," Item Two "}}
The solution I proposed works
var sourceDictionary = serviceAgent.GetSampleDictionary(); // Simplified for brevity var filteredDictionary = sourceDictionary.GroupBy(s => s.Value) .Where(group => @group.Any()) .Select(g => g.First()) .ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
Question Am I doing too much logic in it? OR, in other words, is there an easier way to do this?
source share