相关疑难解决方法(0)

是否可以通过反射获得局部变量?

我有一个至少有50个局部变量的方法.我需要从字符串值中选择一个变量.是否可以使用C#反射访问局部变量?

编辑:

void A()
{
    var a1 = List<MyClass>();
    var a2 = List<MyClass>();
    var a3 = List<MyClass>();
    var a4 = List<MyClass>();
    var a5 = List<MyClass>();
    ........................
    ........................
    ........................
    // I have a string value found at runtime. The possible values of it are a1,a2,a3,a4,a5,.... I need to select one
}
Run Code Online (Sandbox Code Playgroud)

c# c#-4.0

2
推荐指数
1
解决办法
1995
查看次数

标签 统计

c# ×1

c#-4.0 ×1