To convert a list to a dictionary, we can do it easily with the follwing:
list.ToDictionary(v=> v, v=>true);
For the first parameter in ToDictionary, I can understand the first parameter is the element of the dictionary. But what is meant by v=> true?
The second parameter should be of the type IEqualityComparer. What purpose does this serve? How is v=> true same as IEqualityComparer?
This is the method is used.
The second parameter (v => true) is the elementSelector (A transform function to produce a result element value from each element).
A list with the elements
1,2and3would result in a dictionary with the following mapping (all values aretrue):