Delegates - Features,Properties - Csharp.Net

Q.  Which of the following are correct?

1. Delegates are like C++ function pointers.
2. Delegates allow methods to be passed as parameters.
3. Delegates can be used to define callback methods.
4. Delegates are not type safe.

- Published on 31 Aug 15

a. 1,3,4
b. 1,2,3
c. 2,3,4
d. All of the above

ANSWER: 1,2,3
 
A delegate is an object that can refer to a method. It means that it can hold a reference to a method. The method can be called through this reference or we can say that a delegate can invoke the method to which it refers. The main advantage of a delegate is that it invokes the method at run time rather than compile time. Delegate in C# is similar to a function pointer in C / C++.
A delegate can call only those methods that have same signature and return type as delegate. So the option 1, 2, 3 are correct.

Post your comment / Share knowledge


Enter the code shown above:
 
(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)