A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 徐赵华 中级黑马   /  2012-10-11 22:03  /  1407 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 徐赵华 于 2012-10-11 23:42 编辑

LINQ查询可以返回两种类型的结果------- 一个枚举,注:可枚举的一组数据,不是枚举类型。一个叫做标量的单一值。

int[] intArray = new int[] { 10, 3, 4, 16, 78, 14 };
            string[] strArray = new string[] { "hello world", "doomsday", "china" };        
            IEnumerable<int> result = from n in intArray        //查询语法
                                      where n < 20
                                      select n;
            foreach (var x in result)
            {
                Console.WriteLine("{0}", x);
            }
            var nums = intArray.Where(x => x < 20);     //方法语法
            int intCount = (from n in intArray              //两种形式的组合
                            where n <= 20
                            select n).Count();
            IEnumerable<string> strResult = from n in strArray
                                            where n == "hello world" || n == "doomsday"
                                            select n;
            foreach (string y in strResult)
            {
                Console.WriteLine(y);
            }

评分

参与人数 1技术分 +1 收起 理由
郑文 + 1

查看全部评分

1 个回复

倒序浏览
值得学习ing!
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马