zoukankan      html  css  js  c++  java
  • LINQ入门语法

    Code

    class IntroToLINQ
    {       
        static void Main()
        {
            // The Three Parts of a LINQ Query:
            //  1. Data source.
            int[] numbers = new int[7] { 0, 1, 2, 3, 4, 5, 6 };

            // 2. Query creation.
            // numQuery is an IEnumerable<int>
            var numQuery =
                from num in numbers
                where (num % 2) == 0
                select num;

            // 3. Query execution.
            foreach (int num in numQuery)
            {
                Console.Write("{0,1} ", num);
            }
        }
    }


    将查询出来的数据添加到一个集合

     
    static void Main(string[] args)
            {     
    // The Three Parts of a LINQ Query:
                
    //  1. Data source.
                int[] numbers = new int[7] { 0123456 };

                List
    <int> numQuery2 = (from num in numbers where (num % 2== 0 select num).ToList();

                
    foreach (int num in numQuery2)
                {
                    Console.WriteLine(
    "{0,1}", num);
                }

               Console.ReadLine();
             
            }

  • 相关阅读:
    汉语-词语-平目:百科
    汉语-词语-平昔:百科
    汉语-词语-平一:百科
    汉语-词语-平居:百科
    汉语-词语-平展:百科
    汉语-词语-平静:百科
    汉语-词语-平心:百科
    汉语-词语-平庸:百科
    汉语-词语-平常:百科
    1231 最优布线问题
  • 原文地址:https://www.cnblogs.com/duwamish/p/1343208.html
Copyright © 2011-2022 走看看