This code is written using LINQ Preview May 2006 CTP.
To run this sample code, you must have Visual Studio 2005 Express or other Visual Studio 2005 versions.
After that, install LINQ Preview May 2006 CTP version from MSDN website.
After installation of LINQ Preview May 2006 CTP, click on New Project in the File menu of Visual Studio 2005, select LINQ Preview in the Project Types and create a LINQ Console Application from the selected templates.
Note:
If you want to write your sample code in VB.NET, Select Visual Basic in the Project types and LINQ in the Templates pane.
See Figure 1.

Figure 1.
As name suggests, LINQ (.NET Integrated Query Language) provides from..where..select syntax to select data from collections.
Understanding from..where..select
The from..where..select syntax in LINQ is similar to SELECT..FROM..WHERE clause of SQL. Here is a simple from..select.
from day in daysArrayselect day;
In the above statement, I select day in daysArray. It returns an object of "var" type, which is a generic type and can store any type. For example, daysArray can be an array of numbers, strings, or even objects. Here is an example of daysArray.
string
[] daysArray = { "Mon", "Tue", "Wed", "Thur", "Fri", "Sat", "Sun" };This is how return value is stored from a from..select statement.
var days = from day in daysArray select day;
Now where clause is used to filter the results. For example, the following syntax gets retuslts from daysArray where value of day is "Wed" only.
var days = from day in daysArray where day =="Wed" select day;
Filtering using where




Join the conversation! Your thoughts help the community grow.