VB:为其他变量的值赋予一个变量名称
问题描述:
我想用另一个变量的名称作为变量名称。VB:为其他变量的值赋予一个变量名称
下面是一个例子:
While loopBool
loopTimes = 0
FolderBrowserDialog1.ShowDialog()
If DialogResult.OK Then
Dim [loopTimes] As String = FolderBrowserDialog1.SelectedPath()
End If
'Some more stuff
End While
我想要[loopTimes]是可变loopTimes的值,但我不能弄清楚。 在此先感谢
答
做到这一点的最好办法是使用字典:
Dim myDict As New Dictionary(Of Integer, String)()
然后,您可以将您的字符串字典:你为什么需要这个
While loopBool
loopTimes = 0 'I'm assuming this is already declared somewhere?
FolderBrowserDialog1.ShowDialog()
If DialogResult.OK Then
myDict(loopTimes) = FolderBrowserDialog1.SelectedPath()
End If
'Some more stuff
End While
?另外,为什么你不能使用字典? –
为什么不使用数组,字典或多种集合类型?即使你可以从中创建静态变量,你以后会如何引用它们?收集完全是为了这个目的。 – David
您无法在运行时更改变量的命名。此外,你为什么要这样做,因为它是不可见的用户。 – phadaphunk