• LINQ小记


     //LINQ 根据长度查询出来
                string[] strs = new string[] { "1", "22", "333", "4444", "55555" };            
                var end = from str in strs where str.Length < 3 select str;
                var i = "";
                foreach (var item in end)
                {
                    i = i + item + "|";
                }
                this.Label1.Text = i.Substring(0, i.Length - 1);


    //LINQ 根据长度分组进行查询
                string[] words = new string[] { "hello", "cup", "vagetable", "mouse", "telephone" };
                var list =
                    from w in words
                    group w by w.Length into lists
                    orderby lists.Key ascending
                    select new { key = lists.Key, value = lists };
                foreach (var item in list)
                {
                    Label2.Text += string.Format("长度:{0},{1}</br>", item.key, string.Join(",", item.value));
                }


     //LINQ 根据同名进行查询
                string[] ss = new string[]
                { "hello", "hello", "cup", "cup", "cup", "vagetable", "mouse", "telephone", "telephone" };
                var l =
                    from s in ss
                    group s by s into lists
                    orderby lists.Key
                    select lists;
                foreach (var item in l)
                {
                    Label3.Text += string.Format("{0},数量:{1}<br/>",item.FirstOrDefault(),item.Count().ToString());
                }

  • 相关阅读:
    org.apache.jasper.JasperException
    泛型接口
    Mysql学习
    深入分析ClassLoader
    空格哥的第一篇Blog
    [Maven] Missing artifact
    sftp新建用户步骤
    遍历map的6种方式
    利用aop插入异常日志的2种方式
    Mybatis-Oralce批量插入方法
  • 原文地址:https://www.cnblogs.com/dabexiong/p/5223042.html
Copyright © 2020-2023  润新知