i have searched on the Google but could not find exactly what the delegate is and when to use delegate? can any one explain me with an example?
You can get it cleared here :
What : http://csharpindepth.com/Articles/Chapter2/Events.aspx
when : http://msdn.microsoft.com/en-us/magazine/cc301810.aspx
A delegate is kind of like a callback, but it allows you to register more than one callback action.
Maybe an example is easier: you have an OnClick delegate. By default, nothing happens. But you can register 1, or 2, or N callbacks which will ALL receive the OnClick event.
Delegate is a concept related to Delegation Design Pattern. Let me point you to the wiki link so you can take over the study from there.
http://en.wikipedia.org/wiki/Delegation_pattern
In simplest terms, a delegate is just like a function assigned to a variable (I'm not sure if that's really what happens under the hood but it helps to think of it like that). If you have programmed in C++, its like the address of a function or the return value of GetProcAddress() but with more functionality and typesafety.
You can call the delegate like regular function, pass it as a function argument (like a regular variable) and it can also be null. Google it again (or visit the links of other posters), there are lots of materials about delegates.
精彩评论