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();
            }
  • 相关阅读:
    ADO.NET(一)数据库连接串的几种写法
    C#事件Event--猫捉老鼠
    事件
    委托
    C# .Net List<T>中Remove()、RemoveAt()、RemoveRange()、RemoveAll()的区别,List<T>删除汇总
    上传下载
    验证数据
    RSADemo2
    随机数
    二维码生成类
  • 原文地址:https://www.cnblogs.com/xtflz/p/5133724.html
Copyright © 2011-2022 走看看