What is a delegate, why should you use it and how do you call it ?



What is a delegate, why should you use it and how do you call it ?..

Answer / ajay vikram

A delegate is a reference type that refers to a Shared method of a type or to an instance method of an object. Delegate is like a function pointer in C and C++. Pointers are used to store the address of a thing. Delegate lets some other code call your function without needing to know where your function is actually located. All events in .NET actually use delegates in the background to wire up events. Events are really just a modified form of a delegate.
It should give you an idea of some different areas in which delegates may be appropriate:
• They enable callback functionality in multi-tier applications as demonstrated in the examples above. <o:p></o:p>
• The CacheItemRemoveCallback delegate can be used in ASP.NET to keep cached information up to date. When the cached information is removed for any reason, the associated callback is exercised and could contain a reload of the cached information. <o:p></o:p>
• Use delegates to facilitate asynchronous processing for methods that do not offer asynchronous behavior.
• Events use delegates so clients can give the application events to call when the event is fired. Exposing custom events within your applications requires the use of delegates.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Sharp Interview Questions

Why do we use readonly in c#?

0 Answers  


if we are updating a database using thread, and mean while application crashes or thread being aborted then what will happen in Database? Rollback or Database will be updated? Please explain with different scenario.

0 Answers  


What is the use of static abstract class

5 Answers   Karur Vysya Bank KVB, Target,


Is char * null terminated?

0 Answers  


What are the Different kinds of methods?

4 Answers   Wipro,






Explain the difference between a namespace and assembly name in .net?

0 Answers  


what are pointer types in c#

0 Answers   Cognizant,


What is gridview c#?

0 Answers  


What is the difference between virtual and override in c#?

0 Answers  


Can multiple inheritance implemented in c# ?

0 Answers  


Difference between ByVal and ByRef?

5 Answers   Microsoft,


Why do we need nullable types in c#?

0 Answers  


Categories