Possible Duplicate:
when & why to use delegates?
I understand most of C# syntax, and I partially understand delegates, but I cannot find any case I would need to use them.
Can you help me understand their place in software development usong some examples? I would be very happy. Thank you.
Delegates are another way of expressing mutual obligations between a code provider and a code consumer.
It’s like “I need someone who can add two ints and returns two ints” and “Hey, I am a method and I can add two ints and I return an int, you can use me”.
From a distant point of view then, asking “why do I need delegates” is like asking “why do I need interfaces”. Just instead of expressing “class contract” you express “method contract”.
What’s interesting is that most cases handled with delegates can be handled with interfaces and vice versa. It’s just that C# gives you more flexibility in chosing between two mechanisms. You don’t have such flexibility in Java for example, where obligations are expressed using interfaces.