C# LINQ where Clause
A LINQ query expression may have where clause that enables you to specify the criteria for filtering the results sequence. The from clause specified in the beginning of LINQ query expression returns each element from the data source sequence and the where clause further specifies which element to be included in the result sequence by applying Boolean predicate condition over each element referenced by the range variable. It includes only those elements in the result sequence for which the specified where condition returns true. As the LINQ query expressions may have multiple sub-query expressions and each sub expression may have where clause. Further each where clause may have multiple predicate sub-expressions.
Syntax for LINQ where Clause
from <range-variable> in <data source sequence object> where <1st condition over range-variable> [logical operator] <2nd condition over range-variable> ...
The above syntax shows that the where clause of LINQ query may have multiple predicate condition tests over the range-variable or element specified in the from clause. You can use logical && and || operators for applying multiple conditions to filter the results.
Example for LINQ where Clause using C# in ASP.Net
int[] numbersArray = { 37, 40, 20, 23, 25, 27, 30, 5, 7, 10, 13, 33, 35, 15, 17 };
var numbers = from n in numbersArray
where n % 5 == 0
select n;
foreach (int number in numbers)
{
Response.Output.Write("{0} ", number);
}
// Output:
// 40 20 25 30 5 10 35 15
In the above C# LINQ where clause example the expression n % 5 == 0 is a predicate that is applied to each element represented by the range variable. It will filter out the results and return the numbers divisible by 5.
Continue to next tutorial: LINQ select Clause using C# in ASP.Net to learn how to shape and type of the result sequence returned after the execution of from clause and where clause condition if any.

* will not be published
* hint: http://www.example.com