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:

Post a Comment

NOTE: Anonymous Commenting has been turned off for a while... The comment spammers are just killing me...

ALL comments are moderated. I will review every comment before it will appear on the blog.

Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...

I reserve, and will use, the right to not approve ANY comment for ANY reason. I will not usually, but if it's off topic, spam (or even close to spam-like), inflammatory, mean, etc, etc, well... then...

Please see my comment policy for more information if you are interested.

Thanks,
Greg

PS. I am proactively moderating comments. Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...