Task 1
Write code that shows delegates and events: a publisher with an event, two subscribers, and one subscriber leaving. Use a somewhere for a calculation.
Global Quest Solutions: write code demonstrating events and delegatesStuck? Hints
- Declare the event with and raise it with
?.Invoke(this, args). - Subscribe a named method, not a lambda, so you can unsubscribe it.
- Where does a fit? A fee rule passed into a method.
Show a solution
Lending.sln · where this file sits
- keyword, not a public delegate field, and you can say why.
- Raised with
?.Invoke, so no subscribers is not a crash. - Event data in a class with read-only properties.
-=used, and the output proves the removed subscriber no longer runs.- A used for a real calculation, not just declared.
- Senior extra: says where it would be , and when it would be a queue instead.