Is it possible to use a custom structure in place of a KeyValuePair?
Instead of
For Each kvp As KeyValuePair(Of class1,class2) In myDict
Dim c1 As kvp.Key
Dim c2 As kvp.Value
Next
I’d like to use
For Each kvp As myKvp In myDict
Dim c1 As kvp.P1
Dim c2 As kvp.P2
Next
I want to use myKvp in place of KeyValuePair(Of class1,class2) only (not for other types).
I tried creating myKvp as
Public Structure myKvp
Public P1 As class1
Public P2 As class2
Public Sub New(_p1 As class1,_p2 As class2)
P1 = _p1
P2 = _p2
End Sub
End Structure
but I get the message
Value of type System.Collections.Generic.KeyValuePair(Of ASP...class1, ASP...class2) cannot be converted to ‘ASP…myKvp’.
You need to explicitly create an instance of
myKvp. You can do it easily with Linq: