在VB.NET中将变量名存储在String中

Nic*_*tch 3 vb.net string variables

我正在尝试将一些变量的名称存储在字符串中.例如:

Dim Foo1 as Integer
Dim Foo1Name as String

' -- Do something to set Foo1Name to the name of the other variable --

MessageBox.Show(Foo1Name & " is the variable you are looking for.")
' Outputs:
' Foo1 is the variable you are looking for.
Run Code Online (Sandbox Code Playgroud)

这将有助于我正在进行的一些调试.

Jon*_*eet 5

好吧,你可以清楚地设置Foo1Name ="Foo1" - 但我强烈怀疑这不是你想要的.

你怎么知道你试图找到哪个变量的名字?大局是什么?你想要什么可能是可能与反思,如果我们谈论的非本地变量,但我怀疑这是无论是不是可行的,或者有更好的办法首先攻击的问题.