LINQ is a set of standard query operators that brings powerful query facilities right into the .NET Framework language such as C# and VB.NET. The LINQ framework brings together the capability of data access with the power of data manipulation.
The following example utilizes LINQ, a few standard query operators, and the IEnumerable<T> interface
to query and process the contents within a defined array.
Here I given example in C#.
private void LINQExample()
{
string[] firstnames = { "John", "Smith", "Dennies", "Bob"};
IEnumerable<string> names = from fn in firstnames
where fn.StartsWith("S")
select fn;
foreach (string name in names)
{
Console.WriteLine(name);
}
Console.ReadLine();
}
The first statement defines an array of first names. The next one is the new statement. A local variable, names in this case, is initialized with a Language Integrated Query expression. The expression contains two query operators. Operators used are where and select. The local variable names expose the IEnumerable<string> interface, which provides the capability to iterate through the collection. The results are created as you start to iterate through them via the foreach statement.