キーを使用してコレクションを作成しましたが、この情報を取得できません。これは私のコードです:
Dim test As Collection = New Collection
test.Add("This is a test", "testkey")
MsgBox(test("testkey").ToString)
最後の行でエラーが発生します:
引数 'Index' は有効な値ではありません。
どうしたの?
キーを使用してコレクションを作成しましたが、この情報を取得できません。これは私のコードです:
Dim test As Collection = New Collection
test.Add("This is a test", "testkey")
MsgBox(test("testkey").ToString)
最後の行でエラーが発生します:
引数 'Index' は有効な値ではありません。
どうしたの?
キーと値のペアを保存する場合は、Dictionaryを使用します。これを行う方法は次のとおりです。
Dim dictionary As New Dictionary(Of String, String)
dictionary.Add("testkey", "This is a test")
MsgBox(dictionary("testkey"))