using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LinqExer2
{
    class Program
    {
        static void Main(string[] args)
        {
            //1、LINQ实例一
            //int[] number = { 2, 4, 3, 5, 7, 21, 34 };
            //var oddNum = from num in number where (num % 2 != 0) orderby num descending select num;

            //foreach (var num in oddNum)
            //{
            //    Console.WriteLine(num);
            //}


            // 2、LINQ实例二
            //var languages = new string[] { "Java","Java23", "C++", "C#", "C", "HPH", "VB", "VC++", ".NET" };
            //var query = from item in languages group item by item.Length into lengthGroups orderby lengthGroups.Key ascending select lengthGroups;
            //foreach (var item in query)

            //{
            //    Console.WriteLine(item.Key);
            //    foreach (var val in item)
            //    {
            //        Console.WriteLine(val);
            //    }
            //}


            // 3、LINQ实例三
            var objs = new object[] { "Java","C++","C#",120,123,};
            var query = objs.OfType<string>();
            foreach (var item in query)
            {
                Console.WriteLine("数据:{0}", item);


            }

            Console.ReadLine();

        }
    }
}

 

posted on 2015-12-10 16:04  王洪洪  阅读(177)  评论(0编辑  收藏  举报