Again, just out of curiosity:
After I have programmed several projects in VB.Net I to my surprise discovered that there are some more than subtle differences between C# and VB.NET LINQ usage.
For example, if we want to group elements by multiple properties (columns) we need to create a new anonymous type explicitly:
var procs = from c in Process.GetProcesses()
group c by new {c.BasePriority, c.Id} into d
select d;
whereas in VB.NET more straightforward syntax will already do:
Dim b = From c In Process.GetProcesses()
Group c By c.BasePriority, c.Id Into Group
Select Group
So, one does not need to create a type with “new” here.
What are the other differences? Is there any good comparison between the LINQ syntax in C# and VB.NET?
There are some differences that I know of, mostly that VB.NET’s LINQ has some hidden gems:
Keymodifier on anonymous types. This allows you to define which properties in the anonymous type are used when comparing anonymous types. As far as I can tell with C#; it uses everything. This is where VB.NET has an actual advantage.Skipoperation as a keyword:Dim returnCustomers = From a In list Skip numToSkip Select aYou can do this in C#; but it has to be through the extension method, there is no syntactic sugar.Skip While:From a In list Skip While someCondition Select aAgain, C# can do this; but only through the extension method.TakeandTake WhileSelectkeyword is optional in VB.NET. If you want to select what is current; then that works fine:Dim shortWords = From l In list Where l.Length < 10in C#; the Select part is required:var shortWords = from l in list where l.Length < 10 select lThose are the additional “features” of VB.NET’s LINQ that I am aware of.
For example; with C#:
And in VB.NET
You can see the documentation for all of these here: http://msdn.microsoft.com/en-us/library/ksh7h19t(v=VS.90).aspx