@ToostR ,Welcome to Microsoft Q&A, based on your description, you have some questions about delegates.
The question When & why to use delegates? in stackoverflow is simliar to your problem and you could have a look.
So could someone please explain what delegates are used for
The first answer describes that By defining a delegate, you are saying to the user of your class, "Please feel free to assign any method that matches this signature to the delegate and it will be called each time my delegate is called".
how to use them, and maybe some examples please
You could refer to the second answer in the above link to guide you how to use delegate and it has a good code example to explain the delagate.
what situations they need to be used in
You could use the delegate when you meet one of the conditions:
- You want to call series of method by using single delegate without writing lot of method calls.
- You want to implement event based system elegantly.
- You want to call two methods same in signature but reside in different classes.
- You want to pass method as a parameter.
- You don't want to write lot of polymorphic code like in LINQ , you can provide lot of implementation to the Select method.
Hope my explanation could helpful for you.
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.