Advanced Usages of Events

In this post, we’ll explore more advanced concepts and techniques related to C# events. These advanced topics will help you become a proficient event handler and enable you to use events in complex scenarios. Custom Event Arguments While events typically use the built-in EventArgs class to convey event information, you can create custom event argument classes to pass additional data to event handlers. Custom event arguments allow you to provide specific context to subscribers. For example, in a file monitoring application, you might create a custom event argument class to include the file name and the type of file change. ...

November 3, 2023 · 5 min · 1020 words · Kamran Sadin

A Guide to EventHandlers and Delegates

In the previous post, we introduced the basic concepts of C# events. Now, let’s dive a bit deeper into event handling and delegates, which are fundamental to working with events in C#. Event Handlers An event handler is a method that gets executed when an event is raised. In C#, event handlers are defined with a specific signature, which typically includes two parameters: object sender: This parameter refers to the object that raised the event. EventArgs e: This parameter holds additional information about the event. In many cases, a more specific event argument class is used to convey relevant data. Here’s a simple example of an event handler: ...

November 1, 2023 · 4 min · 746 words · Kamran Sadin