A delegate is a type safe function pointer. That is it holds a reference or pointer to a method.
The signature of the delegate must watch the signature of the function. The delegate points to, otherwise you get a compiler eroor, that is the reason delegates are called as type safe function pointer.
It is just like a class. we can create an instance of it. And when you do so, you pass in the function name as a parameter to the delegate constructor and it is to this function the delegate will point to.
you can declare delegate like this
C#
public delegate int PerformCalculation(int x, int y);
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
A delegate is a type safe function pointer. That is it holds a reference or pointer to a method.
The signature of the delegate must watch the signature of the function. The delegate points to, otherwise you get a compiler eroor, that is the reason delegates are called as type safe function pointer. It is just like a class. we can create an instance of it. And when you do so, you pass in the function name as a parameter to the delegate constructor and it is to this function the delegate will point to.
you can declare delegate like this
C#