Delegate?

arun_mrk

Regular
Joined
Apr 1, 2003
Messages
51
Location
beijing
i been working in dotnet (asp.net with c#) for last 4 months.
But still i dont understand what a 'Delegate' mean.
Could some one help me out in defining its importance as well where to use it?
 
[mshelp]ms-help://MS.VSCC/MS.MSDNVS/csref/html/vcrefTheDelegateType.htm[/mshelp]

A delegate is used if you want to pass a specific function as a
parameter to another function, and then that delegate will be
used within the function called.

In other words, you can create many functions with the
same signature that do different things (string parsing, for example),
and then pass one of those to ANOTHER function so that it is
called.

Sorry if that's confusing... look at the examples given in the MS
help for a better idea.
 
Hopefully I won't confuse anyone further...

I think of delegates like class interfaces, except they're more generic. You declare an interface, then create an object of that interface and point it to a function that shares the same interface (same return type and paremeters). Then, through that interface, you can use the function(s) in which it points to.

The link Bucky gave you has excellent examples. Delegates in C# are mostly used to determine which events point to which functions.
 
Back
Top