How to call an appropriate method by string value from collection?

后端 未结 3 647
孤街浪徒
孤街浪徒 2021-01-28 13:06

I have a collection of strings. For example,

string[] coll={\"1\", \"2\", \"3\" ...\"100\"...\"150\"...} 

and I have respective methods for th

3条回答
  •  天命终不由人
    2021-01-28 13:45

    You can use dynamic invocation

     var methodName = "Method" + selector;
     var method = this.GetType().GetMethod(methodName);
     if (method == null)
     {
        // show error
     }
     else
        method.Invoke(this, null);
    

提交回复
热议问题