Skip to content

Instantly share code, notes, and snippets.

@DominicFinn
Created May 18, 2013 14:13
Show Gist options
  • Save DominicFinn/5604543 to your computer and use it in GitHub Desktop.
Save DominicFinn/5604543 to your computer and use it in GitHub Desktop.
A basic example of an array of anonymous types and then using anonymous functions to filter that array.
Module LambdasAndAnonymousFunctions
Sub Main()
Dim people = {
New With {.Name = "Mick", .Age = 12},
New With {.Name = "Michelle", .Age = 24}
}
Dim nameBeginsWithM = Function(name) name.ToUpper.StartsWith("M")
Dim ageIsEven = Function(age) age Mod 2 = 0
Dim peopleOver20 = people.Where(Function(person) person.Age > 20)
Dim peopleWithNamesThatBeginWithM = people.Where(Function(person) nameBeginsWithM(person.Name))
Dim peopleWithEvenAges = people.Where(Function(person) ageIsEven(person.Age))
End Sub
End Module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment