Thursday, February 07, 2008

VB 9 - Funky Func Functions - The new Func Keyword

Wriju's BLOG - VB.NET 9.0: Lambda Expression Function

"If you want to use Lambda Expression as reusable function, you need to use Func. By using the Func we are actually calling in-build delegate.

So if you write

Dim sqr As Func(Of Double, Double) = Function(x) x * x

Then you can use it in you application to get the square of a number.

Console.WriteLine(sqr(2))

Console.WriteLine(sqr(8))

This could be used in multiple places with different parameter as you generally do with any function." [Post Leached in Full]

I don't know what it is, but I'm having a hard time wrapping my head around the new Lambda Expression feature in VB9. It's just not clicking yet. Oh, I understand what it is, and why it's cool and all that, but just the mechanics of writing Lambda Expressions (Func = Function calls like the one above) still hasn't sunk in.

As with most new things, I need to use it some more so it will sink in. And maybe decomposing it to a syntax I'm used to will help...

Kind of like this;

  Function sqr(ByVal x As Double) As Double
Return
x * x
End Function

... Yeah, I think that helps...

No comments: