A function can have one or more parameters of different data types,
but what if you want to pass a function itself as a parameter?
How does C# handle the callback functions or event handler?
The answer is - delegate.
A delegate is like a pointer to a function. It is a reference type
data type and it holds the reference of a method.
All the delegates are implicitly derived from
System.Delegate class.
Advantages
Encapsulating the method's call from caller
Effective use of delegate improves the performance of application
Used to call a method asynchronously
Declaration
public delegate type_of_delegate delegate_name()
Note
You can use delegates without parameters or with parameter list
You should follow the same syntax as in the method
(If you are referring to the method with two int parameters and int return type,
the delegate which you are declaring should be in the same format. This is why it is referred to as type safe function pointer.)
Tags:
Interview
Salesforce User-Experience-Designer exact questions answer
ReplyDelete