无为

无为则可为,无为则至深!

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  190 Posts :: 291 Stories :: 258 Comments :: 0 Trackbacks
它是Language Integrated Query。
当我们要对数据库表进行查询的时候,我们一定会编写"select * from sometable where ID = .."的语句。好,那我们现在根据LINQ的语法,完全可以将我们熟悉的SQL中像"select","from","where"等语句在.NET Framework环境中顺利使用并且大大提高开发的效率。

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

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

2. 下载安装待完毕。

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

4. 输入代码如下:   

 1
 2using System;
 3using System.Collections.Generic;
 4using System.Text;
 5using System.Query;
 6using System.Xml.XLinq;
 7using System.Data.DLinq;
 8
 9namespace 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 ...



凡是有该标志的文章,都是该blog博主Caoer(草儿)原创,凡是索引、收藏
、转载请注明来处和原文作者。非常感谢。

posted on 2006-06-10 12:56 草儿 阅读(342) 评论(0)  编辑  收藏 所属分类: DotNet

只有注册用户登录后才能发表评论。


网站导航: