Tzah 2.0


Posts Tagged ‘Object initializers’

C# 3.0: Lambda Expressions, extension methods and Object Initializers

Friday, January 23rd, 2009

I just finished reading Alex Yakhnin’s post about generic control creation for WinForms. This is an excellent article  for those whishing to know how to use some of C# 3.0 neatest features like Lambda Expressions, Extension Methods and Object Initializers.

Alex demonstrate how, using these features, nerd developers like us can make their code more readable and as a result – maintainable. Basically, he used Extension methods to extends Control class functionality to create inherited controllers. One of the arguments used in the extension method is Func<Control, T> build.  This is a in fact a nice way to say that ‘build’ is a function that accepts an argument of  Control type, and has a return a value of type T.

Next, he uses Lambda expression to present the function in an elegant way. The expression is in fact, a constructor for the control we wish to build. As a final ingredient in this wonderful code soup, he used Object Initializers for the constructor.

Jajah is the VoIP player that brought you web-activated telephony.