Dynamically Invoke a Type Member - CSharp Reflection

CSharp examples for Reflection:Member

Description

Dynamically Invoke a Type Member

Demo Code


using System;/*from www  . j  a v a2  s. c  om*/
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

class MainClass
    {
        static void Main(string[] args)
        {
            // create an instance of this type
            dynamic myInstance = new MainClass();

            // call the method dynamically
            myInstance.printMessage("hello", 37, 'c');

        }

        public void printMessage(string param1, int param2, char param3)
        {
            Console.WriteLine("PrintMessage {0} {1} {2}", param1, param2, param3);
        }
    }

Result


Related Tutorials