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();
             
            }

  • 相关阅读:
    LOJ #6008. 「网络流 24 题」餐巾计划
    P2144 [FJOI2007]轮状病毒
    随记
    1010: [HNOI2008]玩具装箱toy(斜率优化)
    HDU 3507 Print Article(斜率优化)
    4819: [Sdoi2017]新生舞会(分数规划)
    POJ 2976 Dropping tests(01分数规划)
    spoj 104 Highways(Matrix-tree定理)
    dp专练
    4152: [AMPPZ2014]The Captain
  • 原文地址:https://www.cnblogs.com/duwamish/p/1343208.html
Copyright © 2011-2022 走看看