r/visualbasic • u/ste_wilko • Mar 04 '20
VB.NET Help Declare and Instantiate List(Of KeyValuePair(Of String, String))
I am trying to code my own Enigma machine for no reason other than I watched a video on how they work and now I'm intrigued.
I'm trying to make an emulation of the wiring of the rotors and the best thing to do looks like the List(Of KeyValuePair(Of String, String)). I know how to add to it, but I just want to fill it during the declaration instead, as the values won't ever change
Now I know how to do it with a simple list, for example
Public wiring as New List(Of String) ({"A", "B"})But if I do it like that for KeyValuePair it throws an error
Public wiring as New List(Of KeyValuePair(Of String, String)) ({"A","B"} {"C","D"})I get an "Overload resolution failed because no accessible 'New' accepts this number of arguments"
How do I do it?
6
Upvotes
1
2
u/JasonHenley Mar 04 '20
Try this:
Let's break down why this works. Firstly, you can declare new List(Of String) like this:
For KeyValuePairs it's different. Note you don't have curly braces.
Then you just nest the two.