Delegates are type-safe function pointers. They allow you to pass methods as arguments to other methods, enabling event handling and callback mechanisms.
Type-safe function pointers.
Purpose: Allow you to pass methods as arguments.
Example:
delegate int MyDelegate(int x, int y);
int Add(int a, int b) { return a + b; }
MyDelegate myDel = new MyDelegate(Add);
int result = myDel(5, 3); // result is 8
Leave a Reply