linq - C# - Access variables in a mixed way? -


hey guys wondering how access variables text, mean ex. below

string variable1; string variable2; methodname(int variablenum){    //let's int 1    //how can access variable1?    //sth variable+"variablenum" } 

edit : well, if variables variablea, variableb, how access them?

using reflection:

public class program {     public static void main(string[] args)     {         test test = new test();         test.methodname(1);     } }  public class test {     private string variable1 = "1";     private string variable2 = "2";      public void methodname(int variablenum)     {         // .instance because not static, .nonpublic because private         const bindingflags flags = bindingflags.instance | bindingflags.nonpublic;         fieldinfo field = gettype().getfield("variable" + variablenum, flags);         string s = (string)field.getvalue(this);               } } 

Comments