C# Programming - Delegates - Discussion

Discussion Forum : Delegates - General Questions (Q.No. 9)
9.
Which of the following statements are correct about delegates?
Delegates cannot be used to call a static method of a class.
Delegates cannot be used to call procedures that receive variable number of arguments.
If signatures of two methods are same they can be called through the same delegate object.
Delegates cannot be used to call an instance function. Delegates cannot be used to call an instance subroutine.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
5 comments Page 1 of 1.

SKR said:   1 decade ago
C also correct.

If you have multiple methods with same signature (return type & number of parameters) and want to call all the methods with single object then we can go for delegates.
(2)

Nicholas Mahbouby said:   1 decade ago
B is wrong because a delegate can use the params keyword.

delegate void Del1(params int[] args);

void Foo(params int[] args) {}

Del1 d = Foo;
d(1);
d(1, 2);
d(1, 2, 3);

C is correct. Delegates are multicast so a single delegate object can call multiple methods of the same signature.

delegate void Del2();

void A() {}
void B() {}

Del2 d = A;
d += B;
d();
(1)

Vishnu said:   1 decade ago
If signatures of two methods are same then we can call two methods by same object it can be done but why?

Sam said:   1 decade ago
I think both c and b points are same. Please correct me if I am wrong with valid point.

Reshma said:   3 years ago
I think c will not be correct because when we are creating the obj of delegate we have to specify method name.

So we have to create different objects of delegate for the different methods but we can use the same signature of the delegate.

Post your comments here:

Your comments will be displayed after verification.