Send mail to the author(s)

    July 23, 2008

    Lambda expressions in .NET Compact Framework 2.0

    There's been a lot of internal discussion today on how to leverage C# 3.0 features without requiring .NET Compact Framework 3.5. Mark has the low down on using extension methods with a little compiler misdirection hack.

    The discussions kicked off because I discovered that you can use lambda expressions with .NET Compact Framework 2.0 projects in Visual Studio 2008. I even twittered about it yesterday. (Note: it didn't take me too long to realize it's not a bug, but due to Visual Studio 2008 using the C# 3.0 compiler.) Code like the following just works -- no hacks required:

    delegate double PowerOf(double x, double y);
    
    static void Main() 
    {
        PowerOf pwr = (x, y) => Math.Pow(x, y);
        double result = pwr(2, 3);
    }

    If you are using Visual Studio 2008 and still need to target .NET Compact Framework 2.0, the little things like this go a long way to creating and maintaining reusable code.

    Comments are closed.