Property Delegates with Anonymous Methods

7 Comments »

No programming language is perfect. In spite of the many strengths of C#, there are still a few gaping holes, including generics variance and property delegates.

A delegate is a reference to a method. Unfortunately, C# currently does not support property delegates, in other words, a reference to a property. But there are a few workarounds, one of which involves anonymous methods.

An anonymous method is a new feature in C# 2.0 that enables you to define an anonymous (nameless) method called by a delegate. Anonymous methods are perfect when there is no need for multiple targets, and the code is relatively short and simple. They also come in handy when you need a delegate to a property.

Read the rest of this entry »

Simplify Delegates with Inferences

No Comments »

Delegates can be tricky to understand. Think of a delegate as a reference to a method (pointer to a function).

Read the rest of this entry »