I have a list of strings. I want to create a Dictionary of string, string, with "Id" as the key for each entry and the contents of the list as the value.
i.e.
myList= { "string1", "string2", ...etc }
and therefore
myDictionary = {{"Id1", "string1"}, {"Id2", "string2"}, ...etc}
I have been trying to create a dictionary using the List.ToDictionary method but to no avail
List.ToDictionary(Of String, String)("Id", Function(p) p.key)
Any help is much appreciated.
IDictionary<string, string> dictionary = list. ToDictionary(pair => pair. Key, pair => pair. Value);
To create an empty dictionary, just go New Dictionary().
Try something like this:-
Dim list As List(of string)
Dim dict As IDictionary(Of String) = list.ToDictionary(Function(p) "Id", Function(p) p)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With