by Larry O'Brien, 3 Leaf Solutions, LLC. Intel Corp.
Since its first release, the .NET Framework has provided delegates, object-oriented types corresponding to a particular method signature. For instance, the following represents a delegate identified as Foo that takes two integers as parameters and returns an integer when executed:
Most .NET programmers quickly become familiar with delegates as event handlers in Windows* Forms programming (an event is actually a delegate that is constrained in certain ways, such as only being invocable by the type in which it is declared). Delegates have broad usefulness, any time a final strategy can be separated from general-purpose routines and the final form of the strategy deferred until a later time; event-handling is just the most obvious example. Delegates are an alternative to maintaining a reference to one or more objects that implement an interface with a single method, a structure that brings to mind such design patterns as Strategy, Observer and Command.
Anonymous functions support in-line specification
In C# 1.x, there is only one way to instantiate a delegate. You use a syntax that is much like instantiating an object, passing in to the delegate constructor the name of some previously defined method whose method signature corresponds to the delegate's method signature (including return type).
In Listing 1, the Foo delegate is instantiated with a reference to the static method Listing1.Plus(int, int) in a manner analogous to the way that the refToMyField object is instantiated with a reference to the static field myField. In C# 1.x, there is no delegate capability similar to the ability of variable to be assigned a value from an in-line specification. C# 2.0, however, supports the following:
![]()
![]() | Getting the bubbles out of code: designing for the Itanium 2 processor by Andrew Binstock, principal analyst, Pacific Data Works LLC. Intel C... |
If you're interested in this topic, these articles may be helpful:
![]() | Intel® Math Kernel Library for Windows The flagship for HPC software, Intel® MKL is a set of highly optim... |
![]() | Integrating Java and Microsoft .NET by Jon Jagger, Content Master Ltd. Intel Corp. The right techniques... |
![]() | Java Graph library v 2.1 demo from Big Faceless Organization The Big Faceless Java Graph library ... |
![]() | .NET client application "no touch" deployment: harness the full processing power of the desktop by Christopher Goldfarb, senior software architect, Intel Software Sol... |
![]() | Data access performance in ADO.NET by Ramesh Theivendran, architect, Borland Software Corp. First publish... |
![]()
Related Jobs:

