Click here to Skip to main content
15,907,906 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
We can perform same thing using delegate and function. So Where will we use delegate and where will we use function.
Posted
Comments
BillWoodruff 22-Jan-16 5:08am    
When you use the word 'function, if you are referring to the type of Delegate in C# named 'Func, then please let us know.

Roughly speaking a delegate is like a function pointer, that is a way to indirectly call a method.
As an example, see my solution to another question: "how to call multiple methods using loop, please help"[^].
More details, for instance, here: oop - Where do I use delegates? - Stack Overflow[^].
 
Share this answer
 
Comments
BillWoodruff 22-Jan-16 23:44pm    
+5 Sometimes I wonder if it's useful (for newcomers) to refer to a Delegate as an indirect reference to a Method, to stress that a Method (in C#) only "exposes" an "executable interface," and the Delegate construct is required to be able to use it without immediate execution.
The delegate object can then be passed to code which can call the referenced method, without having to know at compile time which method will be invoked.

Delegates are especially used for implementing events and the call-back methods.
 
Share this answer
 
v2
A function is the norm. Use delegates where a function doesn't work, like here.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900