ARTICLE

Dynamically Call a Function in C#

Posted by Ibrahim Ersoy Articles | .NET Assemblies July 08, 2012
This article helps you execute a function in runtime.
Reader Level:

As you well know, "dynamic" keyword was introduced in .NET 4.0. While we use dynamic, the c# compiler will not know whether it exists or not. It'll be created & executed in runtime. To call a function dynamically, all you have to do is creating an instance of the class you're in and call the function using the dynamic instance created.

For example we have a class and a function:

class Ersoy
{

    public void Display_Name(string name1)

    {

        Messagebox.Show(name1);

    }

}


We can load a functional dynamically by using:


class
Ersoy
{

    public void Create_Dynamic()

    {

        dynamic ersinstant = new Ersoy();

        ersinstant.Display_Name("Ibrahim");

    }

    public void Display_Name(string name1)

    {

        Messagebox.Show(name1);

    }

}


After running we'll be displaying our name.

Login to add your contents and source code to this article
post comment
     

Thank you Jean! Glad you liked it

Posted by Ibrahim Ersoy Jul 10, 2012

That's a good one Mr.Ibrahim!

Posted by Jean Paul Jul 09, 2012
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.
Get Career Advice from Experts