Using .ToDictionary()

Edit

The ToDictionary() method has an overload that takes two lambda expressions (nitpick: delegates); one for the key and one for the value.

For example:

var myDic = GetSomeStrings().ToDictionary(x => x, x => x.Number('A'));

Note that the values returned by GetSomeStrings() must be unique.


.Net’s Dictionary<TKey, TValue> is unordered; it cannot be sorted at all.

Instead, you can sort the dictionary when you use it, like this:

foreach(KeyValuePair<string, int> kvp in dict.OrderBy(kvp => kvp.Value))

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)