C# Interview Questions on Delegates

1) What is delegate ?

Ans) Delegate is a type which  holds the method(s) reference in an object. It is also referred to as a type safe function pointer.
Using delegates we can pass methods as a parameters. To pass methods as a parameter to delegate, the signature of the method must match of the signature of the delegate.


2) What is the syntax of the delegate?

Ans) public delegate return_type delegate_name(parameters);

3) What are the advantages of delegate?

Ans)  1. Effective use of delegate improves the performance of application
          2. Used to call a method asynchronously

4) Can you check the following code compile?


Ans) No, the code does not compile. For the code to compile, the signature of MethodTest should match the signature of TestDelegate. 

No comments:

Post a Comment