Delegate(s): A delegate is a reference type variable that holds the reference to a method.
1. Declare Delegate:Following is a syntax for declaring a delegate
delegate <return type> delegatename(parameter....)
e.g.
delegate int Add(int x, int y);
If you feel problem to remember syntax of declaring delegate, just remember how we declare n abstract method and prefix delegate keyword instead of abstract keyword.
2. Create object of delegate
Add _a;
3. Pass method which need to be called by delegate
There are three methods by which we can invoke or call delegate
- Named methods
- Anonymous methods
- Lambda Expression
1. Named Method-This is the traditional method which is available from detent 1.0.mechanism .In this we create a method and pass it to object of delegate we had created in Step 2
Join the conversation! Your thoughts help the community grow.