Skip to Content
ASP.NET 3.5 For Dummies®
book

ASP.NET 3.5 For Dummies®

by Ken Cox
February 2008
Intermediate to advanced
428 pages
8h 52m
English
For Dummies
Content preview from ASP.NET 3.5 For Dummies®

7.2. LINQing with From, Where, and Select

LINQ adds a bunch of keywords to Visual Basic. If you've worked with SQL statements, you'll recognize many of the keywords, especially From, Select, and Where. This section shows how these popular clauses work, including samples of their syntax.

NOTE

In a LINQ query, you declare a variable to hold the return value (for example, Dim q), but you don't have to declare what type of variable it is (such as String or Boolean). LINQ uses anonymous types because it often deals with data that contains multiple types that aren't compatible. When LINQ can't tell you what type a query returns, LINQ just makes up a type and passes it off as anonymous.

In Visual Basic, a LINQ expression must appear as one statement; thus, one line can become very long. To break the line and improve readability, Visual Basic supports a space followed by an underscore character (_) as you see in the examples.

7.2.1. Targeting the source in a From...In clause

A From clause points to the source collection (data or objects) and declares an iteration variable. You use an iteration variable as a temporary representative for one item in a collection of items. In the following example, tz is the iteration variable, and System.TimeZoneInfo.GetSystemTimeZones returns the collection:

Dim q = From tz In System.TimeZoneInfo.GetSystemTimeZones

The preceding statement goes In the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

ASP.NET 3.5 Unleashed

ASP.NET 3.5 Unleashed

Stephen Walther
ASP.NET 4 Unleashed

ASP.NET 4 Unleashed

Stephen Walther, Kevin Hoffman, Nate Dudek

Publisher Resources

ISBN: 9780470195925Purchase book