-1

I have the Vb code below i would like to know why it is failing at i. I have done this is C# and it works fine.

Dim numbers = Enumerable.Range(1, 4).OrderBy(i >= ran.Next()).ToList()
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
user3086751
  • 205
  • 4
  • 18

1 Answers1

4

Because that is not valid syntax in VB.NET, you need the ugly Function keyword:

Dim numbers = Enumerable.Range(1, 4).OrderBy(Function(i) i >= ran.Next()).ToList()

In VB.NET i almost always try to avoid that keyword, it hurts my eyes. So you can use this:

Dim numbers = From n In Enumerable.Range(1, 4)
              Order By n >= ran.Next()
Dim numList As List(Of Int32) = numbers.ToList()

But if you want to order randomly this should work:

Dim numbers = From n In Enumerable.Range(1, 4)
              Order By ran.Next()
Dim numList As List(Of Int32) = numbers.ToList()
Community
  • 1
  • 1
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939