_06DemoDelegate
)This example shows the fundamental concept of delegates in C#.
delegate bool MyDelegate(int i);
bool
and taking an int
parameterMyDelegate pointer = new MyDelegate(Check);
Check
methodbool result = pointer(20);
Check(20)
directly, we create a delegate pointerCheck
methodpointer(20)
is called, it executes Check(20)
and returns true
(since 20 > 10)True
_07Demo
)This shows how delegates can be passed as parameters to enable loose coupling between classes.