How to use LINQ where clause to filter results in VB.NET

Web developer can modify the where clause in LINQ statement to filter the results and to include only those that match a specific condition. The next code shows how to find clients who have a last name that starts with a specific letter:

C# in Depth, 3rd EditionManaged Windows VPS Hosting

Dim matches = From client In clients _

Where client.LastName.StartsWith(“D”) _

Select client


Web developer can combine multiple conditional expressions with the And and Or operators, and he/she can use relational operators (such as <, <=, >, and >=) in conjunction with hard-coded values or other variables. For example, Web developer could create a query like this to filter out products greater than a certain price threshold:


Dim matches = From product In products _

Where product.UnitsInStocks > 0 And product.UnitPrice > 75.0 _

Select product