public class AirCraft{ private string m_Name; public string Name { get { return m_Name; } set { m_Name = value; } } private int m_Speed; public int Speed { get { return m_Speed; } set { m_Speed = value; } } public void ShowName() { MessageBox.Show("Aircraft name is " + Name); } public void StartFly() { MessageBox.Show(Name+" Is Flying...(Speed:"+Speed+" km/h)"); } public void StopFly() { MessageBox.Show(Name+" Landed Safely"); }}
public class Form1 : Form{ public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { AirCraft obj = new AirCraft(); obj.Name = "Black Bird"; obj.Speed = 1000; InvokeMethod(obj, "ShowName"); InvokeMethod(obj, "StartFly"); InvokeMethod(obj, "StopFly"); } private void InvokeMethod(object instance,string methodName) { //Getting the method information using the method info class MethodInfo mi = instance.GetType().GetMethod(methodName); //invoing the method //null- no parameter for the function [or] we can pass the array of parameters mi.Invoke(instance, null); }}