Friday, 22 November 2013

What is LINQ and Example 


Language-Integrated Query (LINQ) is a set of features introduced in Visual Studio 2008 that extends powerful query capabilities to the language syntax of C# and Visual Basic. LINQ introduces standard, easily-learned patterns for querying and updating data, and the technology can be extended to support potentially any kind of data store. Visual Studio includes LINQ provider assemblies that enable the use of LINQ with .NET Framework collections.

 SQL Server databases, ADO.NET Datasets, and XML documents.

Language-Integrated Query (LINQ) is the name for a set of technologies based on the integration of query capabilities directly into the C# language (also in Visual Basic and potentially any other .NET language).

With LINQ, a query is now a first-class language construct, just like classes, methods, events and so on.

Example :

class LINQQueryExample
{
    static void Main()
    {

        // Specify the data source. 
        int[] scores = new int[] { 97, 92, 81, 60,10,45,100,200 };

        // Define the query expression.
        IEnumerable<int> scoreQuery =
            from score in scores
            where score > 80
            select score; 
 
         SQL Syntax : select * from socres where column >80
  
       // Execute the query. 
        foreach (int i in scoreQuery)
        {
            Console.Write(i + " ");
        }            
    }
}
 
Result 81,92,97,100,200





No comments:

Post a Comment