From the course: C# Essential Training 2: Generics, Collections, and LINQ

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Understanding events

Understanding events

- [Instructor] Another case where we want to use delegates is when we want to raise events. And this is what's often referred to as a multicast delegate, meaning I'm going to be able to invoke a method once in my code, but it may then trigger or invoke many different delegates. So, I'm going to come into my class and declare this event. So, we're in a static class, so it needs to be static. We use the keyword event, then I need the delegate. What is the signature for this event? When I go and raise this event, or I call all these delegates, what is that signature? And here, I've used my delegate that I've defined with a string input. Then I need a name for my event. So, we'll just keep it simple here, something happened. Now we have an event, what are we going to do with it? Well, we can invoke it or raise it. So, I'm going to just paste this bit in here, got a method, do something. I'm going to WriteLine, I'm about to do…

Contents