Created
May 18, 2013 14:13
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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