Looking for startup ideas.? Visit Reinventor.ca

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)
        {
            try
            {
                Type thisType = this.GetType();
                MethodInfo theMethod = thisType.GetMethod(mehtod);
                object[] a = { (object)Parameters };
                string re = theMethod.Invoke(this, a).ToString();
                return re;
            }
            catch
            {
                return "Internal Server Error";
            }
        }

Thanks and Visit agian.

#Jassie



Share this:

ABOUT THE AUTHOR

Hello We are OddThemes, Our name came from the fact that we are UNIQUE. We specialize in designing premium looking fully customizable highly responsive blogger templates. We at OddThemes do carry a philosophy that: Nothing Is Impossible

0 comments:

Post a Comment