C# : Call Class Method Using Name From String

Hello, Today i am going to share a code snippet for how to call a method using string name. Its very simple technique you can easily achieve it using following code Snippet.

Please note hat i have considered the return type of calling function to be string
public string calldynamicMethods(string mehtod, string Parameters)
                Type thisType = this.GetType();
                MethodInfo theMethod = thisType.GetMethod(mehtod);
                object[] a = { (object)Parameters };
                string re = theMethod.Invoke(this, a).ToString();
                return re;
                return "Internal Server Error";

Thanks and Visit agian.



Post a Comment