C# Programming - Delegates - Discussion
Discussion Forum : Delegates - General Questions (Q.No. 9)
9.
Which of the following statements are correct about delegates?
Discussion:
5 comments Page 1 of 1.
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.
So we have to create different objects of delegate for the different methods but we can use the same signature of the delegate.
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.
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();
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)
Sam said:
1 decade ago
I think both c and b points are same. Please correct me if I am wrong with valid point.
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?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers