Delegates and Events

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/13

flashcard set

Earn XP

Description and Tags

Flashcards covering C# delegates, generic delegates, comparison with interfaces, and event handling concepts based on IT1811 Handout 1.

Last updated 5:34 PM on 9/7/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

14 Terms

1
New cards

What is a delegate in .NET?

A delegate is a class in .NET that encapsulates a method and serves as a reference type data type that holds a reference to a method.

2
New cards

What is the general syntax for declaring a delegate in C#?

delegate ();
3
New cards

What requirement must be met for a delegate to reference a method?

The delegate's signature (return type and parameter count/types) must match the signature of the referenced method.

4
New cards

What are two ways to instantiate a delegate in C#?

By using the new keyword with a method reference (e.g., GetAnswer mdAdd = new GetAnswer(Formula.getSum);) or by direct method assignment (e.g., GetAnswer mdAdd = Formula.Addition;).

5
New cards

What is a generic delegate type?

A delegate that is not bound to any specific data type and can reference a method that returns and takes parameters of different types.

6
New cards

What example code is given in the handout for declaring a generic delegate?

public delegate X DisplayOutput(X arg);

7
New cards

How do delegates and interfaces compare regarding method implementation capacity?

Delegates can implement a method only once and are used when a class needs more than one implementation, whereas a class implementing an interface can implement all methods associated with it.

8
New cards

How do delegates and interfaces compare in terms of execution and retrieval speed?

Delegates are faster to execute but slower to get, whereas interfaces are slower in executing but faster to get.

9
New cards

What is an event in C#?

An event is a member of a class that acts as a task initiator and is fired whenever a specific action takes place.

10
New cards

What are event handlers?

Event handlers are the methods that are automatically invoked when an event occurs.

11
New cards

What must be declared prior to declaring an event?

A delegate to which the event will be associated must be declared first.

12
New cards

What is the syntax for declaring an event in C#?

public event delegate_name event_name;

13
New cards

What operator and syntax are used to add a delegate to an event?

The += operator is used with the syntax: event_name += delegate_instance;

14
New cards

What are event accessors and what functions do they perform?

Event accessors are the add and remove methods generated by the compiler; add registers a new subscription to an event, while remove unregisters a subscription.