Showing posts with label how to create delegate. Show all posts
Showing posts with label how to create delegate. Show all posts

Thursday 6 February 2020

delegate in C#

 public class Test1
    {

       // Create Delegate
        public delegate int AddDel(int a, int b);   
   
        public int Add(int a, int b)
        {
           return a + b;
        }
        public  void TestM()
        {
            // Create instance of Delegate and pass method as a parameter
            AddDel addDel = new AddDel(Add);

            addDel.Invoke(10, 20);
        }
    }

Note: Method parameter and return type must be same as delegate