1.NET Language Integrated Query(LINQ):不采用特定于关系数据库或者XML的专有方案,而采用通用方案来解决各种信息源的访问与整合问题。
2.在LINQ中,查询成为编程语言的一个组成部分,这使得查询表达式可以得到很好的编译时语法检查,丰富的元数据,智能感知等强类型语言的好处。
语法格式:
class Program
{
static void Main(string[] args)
{
string[] names = { "burke", "Connor", "Frank", "Everett", "Albert", "Geroge", "Harris", "David" };
IEnumerable<string> query = from s in names
where s.Length == 5
orderby s
select s.ToUpper();
foreach (string item in query)
{
Console.WriteLine(item);
}
Console.ReadLine();
}
}
以上:{
static void Main(string[] args)
{
string[] names = { "burke", "Connor", "Frank", "Everett", "Albert", "Geroge", "Harris", "David" };
IEnumerable<string> query = from s in names
where s.Length == 5
orderby s
select s.ToUpper();
foreach (string item in query)
{
Console.WriteLine(item);
}
Console.ReadLine();
}
}
IEnumerable<string> query = from s in names
where s.Length == 5
orderby s
select s.ToUpper();
等同于
IEnumerable<string> query = from s in names
where (s=>s.Length == 5)
orderby (s=>s)
select (s=>s.ToUpper());
等同于如下委托:
Func<string,bool> filter = delegate(string s){
return s.Length == 5;}
Func<string,string> extract = delegate(string s){
return s;}
Func<string,string> project = delegate(string s){
return s.ToUpper();};
IEnumerable<string> query = names.Where(filter)
.OrderBy(extract)
.Select(project);
return s.Length == 5;}
Func<string,string> extract = delegate(string s){
return s;}
Func<string,string> project = delegate(string s){
return s.ToUpper();};
IEnumerable<string> query = names.Where(filter)
.OrderBy(extract)
.Select(project);