1/18
Vocabulary-style flashcards covering key terms from the lecture notes on Delegates and Events.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Delegate
A .NET class that encapsulates a method; a reference type that holds a reference to a method and can call methods with a matching signature.
Delegate signature
The return type and parameter list that must match the referenced method so the delegate can invoke it.
Declaring a delegate
Using the delegate keyword to declare a delegate in a class, specifying access modifier, return type, name, and parameters.
Instantiating a delegate
Creating a delegate instance using new or by assigning a method reference.
Invoking a delegate
Calling the method referenced by the delegate by invoking the delegate with appropriate arguments.
Generic delegate
A delegate not bound to a specific type, capable of referencing methods with different parameter and return types using a type parameter.
DisplayOutput
A generic delegate that takes a single parameter of type X and returns a value of type X.
Difference: delegates vs interfaces
Delegates are declarations with no implementation used as safe callbacks; interfaces declare methods that classes implement.
Event
A member of a class that fires when a specific action occurs and invokes its registered event handlers via delegates.
Event declaration
Declaring an event by declaring a delegate first, then using 'public event
Event subscription
Adding a handler to an event using the '+=' operator.
Event accessors
Compiler-generated add and remove methods for an event; can be customized with code in the accessors.
Add accessor
Code that runs when a new subscriber is added to an event.
Remove accessor
Code that runs when a subscriber is removed from an event.
Reference method
A method that is referenced by a delegate.
Parameter count matching
The delegate must have the same number of parameters as the referenced method.
Return type matching
The delegate's return type must match the referenced method's return type.
Static method reference
A static method can be referenced by a delegate.
Event handler
The method that is invoked in response to an event.