LINQ 初探

翻译|其它|编辑:郝浩|2007-08-29 10:58:50.000|阅读 1090 次

概述:

# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>

LINQ  是什么?


LINQ 
  Language Integrated Query  的简称。


当我们要对数据库表进行查询的时候,我们一定会编写"select * from sometable where ID = .."的语句。好,那我们现在根据  LINQ  的语法,完全可以将我们熟悉的  SQL  中像"select","from","where"等语句在 .NET Framework  环境中顺利使用并且大大提高开发的效率。

下面我就牛刀小试,做个  demo  看看。

1. 先下载  LinQ  框架 
    
现在最新版本是20065月发布"Orcas CTP", 下载地址(这里 )

2. 下载安装待完毕。

3. 新建一个"LINQ Console Application"项目。

4. 输入代码如下:   

 1  2 using System;
 3 using System.Collections.Generic;
 4 using System.Text;
 5 using System.Query;
 6 using System.Xml.XLinq;
 7 using System.Data.DLinq;
 8
 9 namespace LINQConsoleApplication1
10 {
11
    class Program
12      {
13
        static void Main(string[] args)
14          {
15
            string[] aBunchOfWords =  {"One","Two", "Hello", "World", 
16

17 "Four", "Five"};
18             var result = 
19             from s in aBunchOfWords // query the string array 
20             where s.Length == 5     // for all words with length = 5
21             select s;               // and return the string
22             foreach (var s in result)  {
23
                Console.WriteLine(s); //print
24             }
25         }
26     }
27 }
28
29


运行结果如下:
Hello
World
print any key to continue ...



标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com

文章转载自:个人博客

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP