C Events – Creating and Consuming Events in Your Application

You almost certainly know what events are in C#. Even if you do not, you’ve probably used them before. What you may not know is how to create your own events. In this video, I am going to introduce you to events and walk you through creating your own events. We will also discuss the features we can take advantage of and what best practices are that we should know about.

Source Code:
Patreon:
Newsletter signup:

0:00 – Intro
1:19 – Demo application walk-through (WinForms)
3:18 – Code behind the demo app
18:28 – Event: Button click
21:21 – Creating and Invoking custom Event
26:35 – Event?.Invoke() explained
30:00 – Listening to and writing code for the Event
34:00 – Creating the custom Event: Event in action and recap
37:12 – Event argument information: debugging
38:42 – Creating Another custom Event (overdraft event)
43:28 – Listening for the event in multiple places
46:33 – Removing Event Listeners from memory
49:00 – Generic EventHandler: Passing class for T
53:39 – why not to use “public set” for properties
59:25 – Exception when to use public set
1:06:13 – Summary

3 EASY WORKING VEHICLES You Didn’t Know You Could Build in Minecraft NO MODS
3 EASY WORKING VEHICLES You Didn’t Know You Could Build in Minecraft NO MODS

Minecraft Tutorial: 3 Simple Redstone & Slime Block Vehicles that are Simple & Easy to Build with NO MODS and Read more

How to Build a Gaming PC in 2021
How to Build a Gaming PC in 2021

Our full 2021 gaming PC build computer tutorial! 🛠 Get a Free 32GB Flash Drive and 32GB Micro SD Card Read more

CRAZY WAYS TO SNEAK PETS ANYWHERE YOU GO || Fun Sneaking Pets And Snacks Hacks
CRAZY WAYS TO SNEAK PETS ANYWHERE YOU GO || Fun Sneaking Pets And Snacks Hacks

Going somewhere and want to take your pet with you, but pets are not allowed? Do not worry! After all, Read more

Funny Ways to SNEAK FOOD FROM PARENTS How to Sneak Snacks Awesome Food Sneaking Ideas by KABOOM
Funny Ways to SNEAK FOOD FROM PARENTS How to Sneak Snacks Awesome Food Sneaking Ideas by KABOOM

There is no way these kids are going on a healthy diet! There are countless ways to sneak snacks from Read more

20 comments

  1. I was wondering if you had any videos or recommendations to learn Add/Remove properties for multiple events. I saw it on the Microsoft website but I’m not sure of its utility nor when to use it. The whole thing with EventList and creating static read only objects

  2. For some reason when I enter 175 or any amount more than my checking account and click purchase it says “withdrew 100”

  3. Tim Corey your videos are amazing I love the free content so much a bought a few of your courses during the black Friday sale. Thank you I have learned so much from your content!

  4. Tim Corey, great job on explaining events and showing how to add custom events. I love C# and use it everyday. This video gave me some new info that will be very helpful!! Thanks.

  5. Thank you Tim for making C# Events so easy to understand that C# beginner can understand. I had a confusion though:
    Am I right in saying that, removal of Events such as recordTransactionsButton_Click, errorMessage_Click is taken care of by Visual Studio but the events such as TransactionApprovedEvent, OverdraftEvent that we create must be removed by us.
    Also, where in the code should I put customer.CheckingAccount.OverdraftEvent -= CheckingAccount_OverdraftEvent; to remove CheckingAccount_OverdraftEvent?

  6. Hi everyone, Tim’s explanation and covering of the event functionality is top-notch, but I’m still a tad confused about the way Tim made the “backupAccount” variable of the “Account” class being a decimal type without calling any type nor Generics. Does that mean if we were to call a class inside a variable and putting values into it then C# will convert the value automatically according to what we typed?
    Now that I let it sunk into a bit more, I realized that it may be due to the value “null”, since Tim defined the “backupAccount” as a “null”, it automatically associated backupAccount to a number.
    Can anyone confirm that?

  7. I started doing C# because was fortunate enough to jojn a good internship program where they use .NET for development. When I discovered your chanell everything suddenly became way easier. Just wanted to let you now and say thank you

  8. People thanking Tim, which I also do, but no one thanks Tim Corey team staff like Tom Thele , so thank you, Tom

  9. 33:50 I couldn’t think of a way to fix the duplication, can you briefly explain what would you do here to fix it?