当前位置: 编程技术>.net/c#/asp.net
在c#中把字符串转为变量名并获取变量值的小例子
来源: 互联网 发布时间:2014-10-22
本文导语: 代码如下:public class Program { public string str = "spp"; public string spp = "Hello World!"; public static void Main(string[] args) { Program p = new Program(); Console.WriteLine(p.G...
代码如下:
public class Program
{
public string str = "spp";
public string spp = "Hello World!";
public static void Main(string[] args)
{
Program p = new Program();
Console.WriteLine(p.GetType().GetField(p.str).GetValue(p).ToString());
Console.ReadKey();
}
}