zoukankan      html  css  js  c++  java
  • 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());
                }

  • 相关阅读:
    MySQL与OLAP:分析型SQL查询最佳实践探索
    创建与删除索引
    第三方推送-个推使用
    test
    图床_搭建本地yum仓库及自制rpm包(无需镜像)
    图床_有趣的linux命令行工具-lolcat
    图床_fdisk一键操作分区-无需脚本
    图床_将你的CentOS 7 配置yum源
    图床_使用Putty远程连接管理Linux实践
    图床_使用Xshell远程连接管理Linux实践
  • 原文地址:https://www.cnblogs.com/dabexiong/p/5223042.html
Copyright © 2011-2022 走看看