假如有一个通信查询变量的值,对面发字段过来,这边返回对应的值,就可以用到如下代码:
using System;
namespace ConsoleApplication1
{
class A
{
public int high = 100;
public string name = "Jarry";
}
class Program
{
public static string str;
static void Main(string[] args)
{
A p = new A();
str = "name";
Console.WriteLine(p.GetType().GetField(str).GetValue(p).ToString());
str = "high";
Console.WriteLine(p.GetType().GetField(str).GetValue(p).ToString());
Console.ReadKey();
}
}
}
对话框显示: