0
0
C Sharp (C#)programming~5 mins

Custom event arguments in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of creating custom event arguments in C#?
Custom event arguments allow you to pass additional data with an event, beyond the standard EventArgs, so event handlers can receive specific information related to the event.
Click to reveal answer
beginner
How do you define a custom event argument class in C#?
You create a class that inherits from EventArgs and add properties to hold the extra data you want to pass with the event.
Click to reveal answer
intermediate
Why should custom event argument classes inherit from EventArgs?
Inheriting from EventArgs follows .NET conventions and allows your custom arguments to be used with standard event patterns and delegates like EventHandler<T>.
Click to reveal answer
beginner
What is the typical signature of an event handler using custom event arguments?
The event handler method usually has two parameters: an object sender and a custom event argument type derived from EventArgs, e.g., void Handler(object sender, MyEventArgs e).
Click to reveal answer
intermediate
How do you raise an event with custom event arguments in C#?
You create an instance of your custom event argument class with the needed data, then call the event delegate passing 'this' as sender and the custom args instance.
Click to reveal answer
What base class should a custom event argument class inherit from?
AObject
BEventArgs
CEventHandler
DDelegate
Which of the following is the correct event handler signature for a custom event argument MyEventArgs?
Avoid Handler(MyEventArgs e, object sender)
Bvoid Handler(object sender)
Cvoid Handler(object sender, MyEventArgs e)
Dvoid Handler()
Why create custom event arguments instead of using EventArgs directly?
ATo avoid using delegates
BTo make events slower
CTo prevent event subscription
DTo pass extra information with the event
How do you raise an event with custom arguments in C#?
ACall the event delegate with sender and new custom args instance
BCall the event delegate with only sender
CCall the event delegate with no parameters
DCall the event delegate with only custom args
Which keyword is used to declare an event in C#?
Aevent
Bdelegate
Cclass
Dvoid
Explain how to create and use custom event arguments in C#.
Think about how to pass extra information with events.
You got /5 concepts.
    Describe the benefits of using custom event arguments instead of the default EventArgs.
    Consider what extra information event handlers might need.
    You got /4 concepts.