Blog

Call class methods using the method name dynamically

Posted 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);


post comment
     
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
Get Career Advice from Experts
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter