Using .ToDictionary()

后端 未结 7 1964
北荒
北荒 2020-12-25 09:27

I have a method returning a List, let\'s call it GetSomeStrings().

I have an extension method on string class, returning number of characters in the str

7条回答
  •  [愿得一人]
    2020-12-25 10:29

    A regular Dictonary is not sorted, but you can use a SortedDictonary:

    var sortedDict = new SortedDictionary(
        GetSomeStrings().ToDictionary(x => x, y => y.Number('A')));
    

    That statement should give you a SortedDictionary sorted by the string key.

提交回复
热议问题