Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
what is a delegate in c# ?Explain in simple way with example please.
Posted
Comments
CPallini 15-Dec-14 6:52am    
For example, a MP is a delegate.

Here you are a good explanation with example:
http://www.tutorialspoint.com/csharp/csharp_delegates.htm[^]
 
Share this answer
 
Comments
Am Gayathri 15-Dec-14 6:29am    
Its a good one thanks.
TheRealSteveJudge 15-Dec-14 6:30am    
You're welcome!
In essence it's a "pointer to a function": it allows you to store the address of a function in a variable and then call it later, without having to know exactly what function you are calling at that point.

This allows you to change what code does without changing the code!
For example, you might have a bit of code which outputs a page of information from yoru database. If you use a delegate, you can make it work to the screen or a printer without changing the actual method at all, by passing it a different "output function" which does the actual output.

There is a lot more to it than that, and you need to read up on it properly: http://msdn.microsoft.com/en-gb/library/ms173171.aspx[^] is worth reading before you submit your homework.
 
Share this answer
 
Comments
Am Gayathri 15-Dec-14 6:25am    
Could you provide some codes if you don't mind.
Am Gayathri 15-Dec-14 6:29am    
Thanks
TheRealSteveJudge 15-Dec-14 9:04am    
Good summary! 5*

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