110,539
社区成员
发帖
与我相关
我的任务
分享
public static void Main()
{
test t = new test();
t.a1 = 10;
string b = "a1";
Type T=t.GetType();
System.Reflection.FieldInfo fi = T.GetField(b);
if (fi != null)
{
int value = (int)fi.GetValue(t);
Console.WriteLine("{0}={1}", b, value);
}
}
struct test
{
public int a1;
public int a2;
public int a3;
}