Using .ToDictionary()

后端 未结 7 1965
北荒
北荒 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:14

    You need to use the overload of ToDictionary which takes two functions:

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

    Both functions take what ever object you are using to create the dictionary. The first produces the Key; the second, the Value.

提交回复
热议问题