Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lambda expressions in c# vs. vb.net

Tags:

c#

vb.net

lambda

Functionally, is there any difference (apart from syntax onbviously) between lambda expressions in C# and VB.Net?

EDIT: following up on CraigTP's answer: any references to the situation in .Net 4?

EDIT: I'm asking because I'm used to C#, but for a next project the customer asks VB.Net. We're not a priori against that. We realize that most language constructs are supported in both languages. However, we're particularly fond of the way C# implements lambda expressions. We would like to have an overview of the differences with VB.Net

EDIT: accepted CraigTP's answer for pointing out what I currently consider the most important difference.

So to summarize: VB.Net 9 does not support multiline statements in a lambda expression, and a lambda must always return a value. Both of these issues are addressed in VB.Net 10

like image 802
jeroenh Avatar asked Jan 20 '10 07:01

jeroenh


1 Answers

There's no functional difference, however, as Joe Albahari says in this forum post:

VB.NET doesn't support multi-statement lambda expressions or anonymous methods.

Note that this is based upon C# 3.0 and VB.NET 9.0 (ie. the Visual Studio 2008 versions of the languages) - I'm not sure if it still applies with Visual Studio 2010 (C# 4.0 and VB.NET 10.0 respectively).

EDIT:

As per Richard Szaley's and my own comments, VB.NET 10.0 (which will be part of Visual Studio 2010) DOES support multi-statement lambdas, and here is a link to an MSDN Channel 9 video that shows off this feature (along with many others!):

Lucian Wischik and Lisa Feigenbaum: What's new in Visual Basic 10

like image 151
CraigTP Avatar answered Oct 15 '22 14:10

CraigTP