24 May 2011

LINQ - Language-Integrated Query - Basics in C# 3.0

LINQ - Language-Integrated Query - Basics in C# 3.0


-To indicate that query is an integrated feature of the developer's primary programming languages.
-Language-integrated query allows query expressions to benefit from the rich metadata, compile-time syntax checking,
static typing and IntelliSense that was previously available only to imperative code .
-The standard query operators allow queries to be applied to any IEnumerable-based information source.
-The extensibility of the query architecture is used in the LINQ project itself to provide implementations
that work over both XML and SQL data.
-The query operators over XML (LINQ to XML) use an efficient, easy-to-use, in-memory XML facility to provide XPath/XQuery
functionality in the host programming language.

simple C# 3.0 program

using System;
using System.Linq;
using System.Collections.Generic;

class app {
static void Main() {
string[] names = { "Burke", "Connor", "Frank",
"Everett", "Albert", "George",
"Harris", "David" };

IEnumerable query = from s in names
where s.Length == 5
orderby s
select s.ToUpper();

foreach (string item in query)
Console.WriteLine(item);
}
}

Output:

BURKE
DAVID
FRANK

-The local variable query is initialized with a query expression. A query expression operates on one or more information
sources by applying one or more query operators from either the standard query operators or domain-specific operators.
This expression uses three of the standard query operators: Where, OrderBy, and Select.

Enumerable query = names
.Where(s => s.Length == 5)
.OrderBy(s => s)
.Select(s => s.ToUpper());

1 comment:

  1. http://msdn.microsoft.com/en-us/library/bb308959.aspx

    ReplyDelete

Comments Welcome

Finding duplicate records in SQL Server

 Finding duplicate records in SQL Server 1. The GROUP BY and HAVING Method This is the most standard approach. It is best used when you on...