normally I am a C# guy, recently I am working on some VB.net code. I just learned that in VB.net you can index into an IEnumerable, a little surprise for me, different from C#.
However, in the following code, I found the indexing not working anymore, I don't know why. What's happening here?
Imports System.Linq
Structure Point
Public X As Double
Public Y As Double
End Structure
Class Circle
Public Property Radius As Double
Public Property Center As Point
End Class
Module Module1
Sub Main()
Dim Circles() As Circle = {
New Circle With {.Radius = 5, .Center = New Point With {.X = 0, .Y = 0}},
New Circle With {.Radius = 5, .Center = New Point With {.X = 10, .Y = 10}},
New Circle With {.Radius = 10, .Center = New Point With {.X = 10, .Y = 10}},
New Circle With {.Radius = 12, .Center = New Point With {.X = 0, .Y = 0}}
}
Dim circleGroups = From c In Circles
Order By c.Radius
Group c By c.Center Into Group
'This is not working, not complile
Dim doubleCircleGroups1 = From g In circleGroups
Where g.Group.Count() = 2
Select Center = g.Center, ID = g.Group(0).Radius * 2, OD = g.Group(1).Radius * 2
'This is working
Dim doubleCircleGroups2 = From g In circleGroups
Where g.Group.Count() = 2
Select Center = g.Center, ID = g.Group.ElementAt(0).Radius * 2, OD = g.Group.ElementAt(1).Radius * 2
End Sub
End Module