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 - C# Tutorial
From the course: C# Essential Training 2: Generics, Collections, and LINQ
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Understanding delegates4m 34s
-
(Locked)
Understanding events8m 2s
-
(Locked)
Common delegates with Action<T> and Func<T>5m 54s
-
(Locked)
Understanding lambda expressions3m 40s
-
(Locked)
Expressions as delegates5m 49s
-
(Locked)
Other uses for expressions2m 13s
-
(Locked)
Solution: Delegate using Func<T>1m 20s
-
(Locked)
-
-
-