LINQ stands for Language INtegrated Query. It is a native querying syntax that allows languages such as C# and VB.NET to filter and enumerate through collections. For example, arrays, data sets and relational databases.
Below are a couple of simple examples as well as some great resources.
–
Sample #1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LinqTest
{
class Program
{
static void Main(string[] args)
{
string[] states = { "TX","LA","FL","AZ","TN","AK"};
var stateList =
from s in states
select s;
Console.WriteLine("State List:");
foreach (var state in stateList)
{
Console.WriteLine(state);
}
}
}
}
Result

–
Sample #2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LinqTest
{
class Program
{
static void Main(string[] args)
{
string[] states = {"TX","LA","FL","AZ","TN","AK"};
var stateList =
from s in states
where s.Substring(0,1) == "A"
select s;
Console.WriteLine("State List:");
foreach (var state in stateList)
{
Console.WriteLine(state);
}
}
}
}
Result

–
Great Resources for LINQ
- LINQ Articles from Scott Guthrie
- Visual Studio 2008 Samples
- 101 LINQ Samples
- Understanding LINQ (C#) – via Amro Khasawneh (Code Project)
–