Call class methods using the method name dynamically

By Hiren Soni Blogs | .NET Assemblies Aug 28, 2010
This blog talks about how we can call a class method using strong method name at run-time.

We can use reflection to call a class and its methods and properties using method and property names. Here is an example where we call a method using the method name.

Before you use this approach, you must import System.Reflection namespace.

using System.Reflection;

Here we create a instance of the class and gets a method instance using the GetMethod method. The Invoke method executes the method.

classdemo c1 = new classdemo();
MethodInfo mi = typeof(classdemo).GetMethod("functionname_in_string_format");
mi.Invoke(c1, null);


COMMENT USING

PREMIUM SPONSORS

Hire Mobile & Web Developer on demand. 100% satisfaction. Try for 1 week or Money Back. Local and remote developers available all over USA.

Latest Blogs