【发布时间】:2011-10-21 11:02:45
【问题描述】:
我需要像这样按名称传递一个变量
Dim html_news = "...the news ..."
Dim var = "news"
Dim a = "html_" & var
' content of that variable
如何在 VB.NET 中做到这一点?
【问题讨论】:
-
为什么你认为你需要这样做?
我需要像这样按名称传递一个变量
Dim html_news = "...the news ..."
Dim var = "news"
Dim a = "html_" & var
' content of that variable
如何在 VB.NET 中做到这一点?
【问题讨论】:
vb.net 并不真正适合您需要做的事情 - 您可以在经典的 asp 和 JavaScript 等脚本语言中完成这类事情。尽管它可能不是“正确”的方法 - 在 Javscript 中使用“eval”函数是不受欢迎的,因为它存在安全风险。我认为下面的代码将以更符合 vb.net 工作方式的方式满足您的需求 -
Dim d As New Dictionary(Of String, String)()
Dim html_news = "...the news ..."
d.Add("html_news","...the news ...")
Dim var = "news"
Dim a = d("html_" & var)
【讨论】: