在 VB.NET 中将变量名存储在字符串中 [英] Store Variable Name in String in VB.NET

查看:33
本文介绍了在 VB.NET 中将变量名存储在字符串中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to store the names of some variables inside strings. For example:

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.

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

This would help with some debugging I'm working on.

推荐答案

好吧,您显然可以只设置 Foo1Name = "Foo1" - 但我强烈怀疑这不是您想要的.

Well, you can clearly just set Foo1Name = "Foo1" - but I strongly suspect that's not what you're after.

您如何知道要查找哪个变量的名称?更大的图景是什么?如果我们谈论的是非局部变量,你想要的可能可以通过反射实现,但我怀疑它要么可行,要么有更好的方法来攻击首先是问题.

How would you know which variable you're trying to find the name of? What's the bigger picture? What you want may be possible with reflection, if we're talking about non-local variables, but I suspect it's either not feasible, or there's a better way to attack the problem in the first place.

这篇关于在 VB.NET 中将变量名存储在字符串中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆