如何期间会为每个在VB.net访问收藏的钥匙?
-
13-09-2019 - |
题
我有一些这样的代码:
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
不隶属于 StackOverflow