如何将字符串转换为变量,vb6/c#/ c ++?

rek*_*101 0 c# c++ string vb6 variables

如何在c#或C++中将字符串转换为变量?

例子(vb6):

dim a as string
dim b as string

b="halo"
a="b"

msgbox a
Run Code Online (Sandbox Code Playgroud)

这应该使输出=晕

这可能吗?..,

谢谢你的回复

Roy*_* T. 5

编辑:

我首先误解了你的答案,但现在我看到(你是Gserg)你希望找到一个基于名字的变量.在C#中,你必须通过反射来做到这一点.请参阅以下代码段,并确保已引用System.Reflection.

MyNamespace.MyClass cls = new MyNamespace.MyClass();
FieldInfo fi = cls.GetType().GetField("FieldName");
string value = (string)(fi.GetValue(null, null));
Console.Out.WriteLine(value);
Run Code Online (Sandbox Code Playgroud)

在这里,我查找该类中的字段"FieldName",然后返回该字段的值

另请参阅GetField的MSDN页面http://msdn.microsoft.com/en-us/library/system.type.getfield(v=vs.71).aspx