どのように私はVB.netの各については時のコレクションのキーにアクセスできますか?

StackOverflow https://stackoverflow.com/questions/1262587

質問

私はこのようないくつかのコード:

Dim col As Collection = New Collection
col.Add(value1, "key1")
col.Add(value2, "key2")

' later...
For Each item As String In col
    ' want to get valueX and keyX here; currently, "item" holds the value
Next

どのように私は、ループ内の値とキーの両方を得ることができますか?多分これが容易になり、別のクラスがあるのでしょうか?

役に立ちましたか?

解決

私は、一般的な辞書を使用すると思います...

 Imports System.Collections.Generic  'at top of file

    Dim col As New Dictionary(Of String, Of Object) 'or whatever type
    col.Add("key1", value1)
    col.Add("key2", value2)    

    For Each item as KeyValuePair(of String, Object) in col
           Console.WriteLine(item.key & ": " & item.value)
    Next
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top