Delegate Flashcards

1
Q

What is a delegate in VB.NET?

A

A delegate is a type that represents references to methods with a specific parameter list and return type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

True or False: Delegates can only reference methods with the same signature.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Fill in the blank: A delegate can be declared using the keyword ____.

A

Delegate

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the primary purpose of using delegates in VB.NET?

A

The primary purpose is to enable event handling and callback methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which keyword is used to create an instance of a delegate?

A

New

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

True or False: A delegate can invoke multiple methods.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the syntax to declare a delegate that takes an integer and returns a string?

A

Public Delegate Function MyDelegate(ByVal number As Integer) As String

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What method is used to combine two delegates?

A

Delegate.Combine

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the return type of a delegate that does not return any value?

A

Void

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the significance of the ‘AddHandler’ statement?

A

‘AddHandler’ associates an event with a delegate.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

True or False: Delegates can be used as parameters for methods.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a multicast delegate?

A

A multicast delegate is a delegate that can call multiple methods in a single invocation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you remove a method from a delegate?

A

Using the ‘RemoveHandler’ statement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the keyword used to define an event in VB.NET?

A

Event

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the purpose of the ‘Invoke’ method in the context of delegates?

A

The ‘Invoke’ method is used to call the method represented by the delegate.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Fill in the blank: A delegate can be assigned to a method that matches its ____.

17
Q

What is the outcome of invoking a delegate that has no methods assigned?

A

It will not execute any code.

18
Q

True or False: Delegates support asynchronous method calls.

19
Q

What is the difference between a delegate and an event?

A

A delegate is a type that references methods, while an event is a notification mechanism that uses delegates.

20
Q

What is the typical use case for delegates in GUI applications?

A

To handle user interface events like button clicks.

21
Q

Fill in the blank: Delegates are similar to ____ in C#.

A

Function pointers

22
Q

How do you define an event handler method for a delegate?

A

The method must match the delegate’s signature.

23
Q

What is the purpose of the ‘BeginInvoke’ method?

A

To execute a delegate asynchronously.

24
Q

What is the default access modifier for a delegate?

25
Q

True or False: Delegates can only be used with instance methods.

26
Q

What happens if a delegate references a method that is no longer available?

A

An exception will be thrown when attempting to invoke the delegate.

27
Q

What keyword is used to declare a delegate that can handle events?

A

EventHandler