VB]如何使用变量名访问变量。 [英] VB] How to access a variable by using the variable name.

查看:144
本文介绍了VB]如何使用变量名访问变量。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。



我想使用变量名来访问变量。 (在视觉基础上)



ex)

Hello.

I want to access a variable by using the variable name. (in visual basic)

ex)

Dim var1 As Double = 1.0
Dim var2 = ByRef GetVariable("var1")
var2 = 2.0    ' Then var1's value changed 2.0





如果不可能,有没有办法使用地图结构?



ex)



If not possible, is there any way to use the map structure?

ex)

map["var1"] = ByRef GetVariable("var1")





请指教。



谢谢。



Please advise.

Thank you.

推荐答案

不,你做不到。

我无法想象这种情况不会令人困惑和危险。

主要问题是var1不存在:它是一个基于本地的堆栈变量,这意味着它首先具有有限的存在(它将在当前方法结束时被释放,因此对它的引用变得极其危险),其次它在最终可执行文件中不存在名称,因为它将被优化为无论如何,IL堆栈。



你认为这是一个好主意你想做什么?
No, you can't do that.
And I can't imagine a situation where that wouldn't be just confusing and dangerous.
The major problem is that var1 doesn't exist: it's a local, stack based variable which means that it firstly has a limited existence (it will be deallocated when the current method ends, so a reference to it becomes extremely dangerous) and secondly that it doesn't exist by name in the final executable as it will be optimised into the IL stack anyway.

What are you trying to do that you think this is a good idea?


这篇关于VB]如何使用变量名访问变量。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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