Posted by : Sudhir Chekuri Tuesday, 27 October 2015

LINQ stands for language integrated query.
It is a simple way to query SQL data, XML data or other C# objects.
It is written along with C# code hence it is known as language integrated query.
LINQ provides intellisense which helps in accurate and easy querying.
Debugging is available for writing complex logics easily.

System.Linq is the namespace used for LINQ.

Types of LINQ:

LINQ to Objects
LINQ to XML
LINQ to DataSeet
LINQ to SQL
LINQ to Entities

Example to query data from C#.NET array in console application:

using System;
using System.Linq;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            //Created array with 5 numbers in it
            int[] array = new int[5] { 3, 7, 1, 7, 5 };
            //Var i contains data retreived using linq query
            //values greater than 5 are retreived
            var i = from s in array where s > 5 select s;
            //Retreived data is printed using for each loop
            foreach (int j in i)
            {
                Console.WriteLine(j);
            }
            Console.ReadKey();
        }
    }
}

Output:
7
7

{ 1 comments ... read them below or add one }

Followers

Total Pageviews

Powered by Blogger.

- Copyright © 2013 DevStudent - Metrominimalist - Powered by Blogger - Designed by Johanes Djogan -