zoukankan      html  css  js  c++  java
  • 关于linq的几个小例子

     private void button1_Click(object sender, EventArgs e)
            {
                int[] numbers = new int[7] { 0,1,2,3,4,5,6};
                var result0 = from num in numbers
                              where (num % 2 == 0)
                              select num;
                foreach (int n in result0)
                {
                    listBox1.Items.Add(n);
                }
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                listBox1.Items.Clear();
                int[] numbers = new int[7] { 2,3,2,4,3,5,5};
                var result1 = from num in numbers
                              where num > 3
                              orderby num descending
                              select num;
                foreach (int n in result1)
                {
                    listBox1.Items.Add(n);
                }
            }
    
            private void button3_Click(object sender, EventArgs e)
            {
                listBox1.Items.Clear();
                int[] numbers = new int[7] { 2, 3, 2, 4, 3, 5, 5 };
                var result2 = from num in numbers
                              where num > 3
                              orderby num ascending
                              select string.Format("当前值为{0}",num) ;
                foreach (string  n in result2)
                {
                    listBox1.Items.Add(n);
                }
            }
    
            private void button4_Click(object sender, EventArgs e)
            {
                listBox1.Items.Clear();
                int[] numbers = new int[7] { 2, 3, 2, 4, 3, 5, 5 };
                int  result3 = (from num in numbers
                               where num > 3
                               select num).Count();
                button4.Text += "--" + result3.ToString();
            }
  • 相关阅读:
    bzoj4513: [Sdoi2016]储能表
    bzoj4000: [TJOI2015]棋盘
    bzoj3067: Hyperdrome
    bzoj4943: [Noi2017]蚯蚓
    bzoj4044: [Cerc2014] Virus synthesis
    bzoj3676: [Apio2014]回文串
    bzoj4543: [POI2014]Hotel加强版
    bzoj1921: [Ctsc2010]珠宝商
    bzoj4754: [Jsoi2016]独特的树叶
    作图的配色
  • 原文地址:https://www.cnblogs.com/xtflz/p/5133724.html
Copyright © 2011-2022 走看看