Understanding the Let Keyword

The Visual Basic syntax offers a keyword named Let that can be used for defining temporary identifiers within query expressions. The following code shows how you can query Windows Forms controls to get a sequence of text boxes:

Dim query = From ctrl In Me.Controls _            Where TypeOf (ctrl) Is TextBox _            Let txtBox = DirectCast(ctrl, TextBox) _            Select txtBox.Name

The Let keyword enables the defining of a temporary identifier so that you can perform multiple operations on each item of the sequence and then invoke the item by its temporary identifier.

Get Visual Basic 2015 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.