Monday, 23 February 2009

My First Lambda Expression ...

Instead of using the following code to bypass an invalid site certificate for the HTTPS web-service I'm using:

System.Net.ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CertificateValidation);
private bool CertificateValidation(
            Object sender,
            X509Certificate cert,
            X509Chain chain,
            SslPolicyErrors Errors)
            return true;

You can use a lambda expression to do the same thing - like this:

System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, cert, chain, Errors) => true);

Sweet ;-)


  1. nice, written with the taste of functional language is always fun :D

    go for F#?

  2. I looked at F# a while ago. Seems interesting.

    To be completely honest dude, this lambda expression was suggested by Resharper and I 'accepted' the suggestion ... I did do the research to back it up, but only after I used it ;-)

    Resharper is so cool - helps you learn new features of the language on-the-fly ...

    Anyway, here's the link to the MS blurb on this cool new feature: