Archive for December 4th, 2008
Delegates in .NET
I received the following question:
What is a delegate? What problem does it solve? and When might I use a delegate?
A delegate is essentially a function pointer. We have used function pointers in various scenarios in the past to solve the problem of needing to execute user-defined code inside of another function or to fire events using the observed/observable programming pattern.
The problem we’ve always had with function pointers in the past is that there has never been any type safety. If I had a variable that was supposed to point to a function, I could assign it any function. So if the function the code is expecting returns a string and takes an integer and a string as parameters, I could assign the variable a function that returned nothing (void) and passed nothing. My code would compile, but when I got to that function, the chances are my code would blow up on me.
Other Related Items:
Teva Men's Riva Leather Event Hiking ShoeYou can tackle any outdoor adventure in Teva's Riva hiking shoe. The durable shoe has a waterproof leather upper that can withstand torrential conditions, and its tractioned vibram outsole can easily tread over any surface. Padded linings will also keep you in maximum comfort along the way.
Samsonite 10485 Delegate II 5-Inch Attache (Black)As the sole global player within the fast growing luggage market, Samsonite has truly secured a leadership position. Travelers everywhere recognize th... Read More >
Learning C# 3.0If you're new to C#, this popular book is the ideal way to get started. Completely revised for the latest version of the language, Learning C# 3.0 ... Read More >

