Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why use delegates? 1

Status
Not open for further replies.

thedougster

Programmer
Jan 22, 2009
56
0
0
US
Why use delegates?

I understand HOW to use delegates, but in what situations would you actually use them? The examples I see in the literature are all in situations where the code could just be written without ever using them.
 
I use them all the time in the form of lambda expressions.
Rhino Mock 3.5
Structure.Map 2.x
Castle Windsor
Linq Expressions

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
a delegate is a description of a function.

if you have an integer, you declare a variable of type byte, int or long.

these types are self-describing, the amount of memory they take up and the maximum and minimum values they can hold are already declared for you.

if you want a variable to store the pointer to a function, you need more information, namely the parameters and return type of that function. this is where delegates come in.

they provide a mechanism whereby you can effectively define your own type.

this type can then be used in exactly the same way you would use int.

having a function take and return a pointer to a function is all very meta and c-like. it makes my head hurt.

hope this helps.

mr s. <;)

 
well said

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top