views:

152

answers:

1

I'm converting from C# this LINQ expression. However, it does not seem to work.

C#

 return (from w in fishSticks
         group w by w.FishQty into g
         orderby g.Key descending
         select g).First().First();

VB

Return (From w In fishSticks
        Group w By w.FishQty Into g()
        Order By g.Key Descending
        Select g).First().First()

Visual Studio turns Into g into Into g() itself and then gives me this error:

Definition of method 'g' is not accessible in this context.

Any ideas?

+3  A: 

VB.Net has different group syntax

The correct syntax is

Dim q = (From w In fishSticks
         Group By Quantity = w.FishQty Into g = Group
         Order By Quantity Descending
         Select g).First().First()
SLaks
I tried this; it actually compiles.
SLaks
Excellent, it works perfectly. VB is the bane of my life. Thanks for your help.
SLC