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

Custom event arguments in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a custom event argument class inheriting from EventArgs.

C Sharp (C#)
public class MyEventArgs : [1] {
    public int Value { get; set; }
}
Drag options to blanks, or click blank then click option'
AEventArgs
BEventHandler
CEvent
DEventArgsBase
Attempts:
3 left
💡 Hint
Common Mistakes
Using EventHandler instead of EventArgs as base class.
Trying to inherit from a non-existent class like EventArgsBase.
2fill in blank
medium

Complete the code to declare an event using the custom event argument class.

C Sharp (C#)
public event EventHandler<[1]> OnValueChanged;
Drag options to blanks, or click blank then click option'
AEventArgs
BMyEventArgs
CValueChangedArgs
DCustomArgs
Attempts:
3 left
💡 Hint
Common Mistakes
Using the base EventArgs instead of the custom class.
Using a class name that was not declared.
3fill in blank
hard

Fix the error in the event invocation by completing the code.

C Sharp (C#)
OnValueChanged?.Invoke(this, new [1] { Value = 10 });
Drag options to blanks, or click blank then click option'
AEventArgs
BEventHandler
CMyEventArgs
DCustomEventArgs
Attempts:
3 left
💡 Hint
Common Mistakes
Using EventArgs instead of MyEventArgs when invoking the event.
Trying to invoke the event with EventHandler instead of event args.
4fill in blank
hard

Fill both blanks to complete the event handler method signature.

C Sharp (C#)
private void [1](object [2], MyEventArgs e) {
    Console.WriteLine($"Value changed to {e.Value}");
}
Drag options to blanks, or click blank then click option'
AOnValueChangedHandler
Bsender
Cargs
DHandleValueChange
Attempts:
3 left
💡 Hint
Common Mistakes
Using invalid method names.
Using incorrect parameter names that do not match event handler conventions.
5fill in blank
hard

Fill all three blanks to subscribe to the event and trigger it.

C Sharp (C#)
MyClass obj = new MyClass();
obj.[1] += [2];
obj.TriggerEvent();

// Event handler method
private void [3](object sender, MyEventArgs e) {
    Console.WriteLine($"New value: {e.Value}");
}
Drag options to blanks, or click blank then click option'
AOnValueChanged
BOnValueChangedHandler
DValueChanged
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching event and handler names.
Using incorrect event names that do not exist.