0

I have 2 functions, one is:

Public Sub PopulateValidKeystrokeList()
    ValidKeystrokeList.Add(Keys.A)
    ValidKeystrokeList.Add(Keys.B)
    ValidKeystrokeList.Add(Keys.C)
    ValidKeystrokeList.Add(Keys.D)
    ValidKeystrokeList.Add(Keys.E)
    ValidKeystrokeList.Add(Keys.F)
    ValidKeystrokeList.Add(Keys.G)
    ValidKeystrokeList.Add(Keys.H)
    ValidKeystrokeList.Add(Keys.I)
    ValidKeystrokeList.Add(Keys.J)
    'backPopulateDictionary()
End Sub

And the other is this:

Public Function backPopulateDictionary(ByRef validkeylist As List(Of String))
    For i As Integer = 0 To ValidKeystrokeList.Count - 1
        keystrokeDictionary.Add(ValidKeystrokeList.Item(i), i)
    Next
    Return keystrokeDictionary
End Function

I need to pass the whole list into backPopulateDictionary() but I'm not sure how to pass a whole list as a parameter, since everything I have tried so far just errors out and doesn't work.

4

1 回答 1

2
Public Function backPopulateDictionary(ByVal validkeylist As List(Of String))
    For i As Integer = 0 To validkeylist.Count - 1
        keystrokeDictionary.Add(validkeylist.Item(i), i)
    Next
    Return keystrokeDictionary
End Function

并调用它backPopulateDictionary(ValidKeystrokeList)

validkeylist是参数,所以当您添加到您的 时keystrokeDictionary,您需要使用参数名称 - 而不是实际列表的名称。

于 2013-07-09T18:10:29.390 回答