zoukankan      html  css  js  c++  java
  • Linq group by, XElement

                if (System.IO.File.Exists(this.textBox1.Text.Trim()) == false)
                {
                    MessageBox.Show("文件不存在!"); return;
                }
                //法2
                XElement globalXmlElement = XElement.Load(this.textBox1.Text.Trim());
                var q = from c in globalXmlElement.Elements("errorInfo")
                        group c by c.FirstAttribute.Value into g
                        where g.Count()>1
                        select new 
                        {
                            Code = g.Key,
                            Cnt =g.Count(),
                        };
               
                /*法1
                List < ErrInfo> infosList = (from c in globalXmlElement.Elements("errorInfo")
                            select new ErrInfo { 
                             Code=c.FirstAttribute.Value,
                             Msg=c.LastAttribute.Value,
                            }).ToList < ErrInfo>();
                var q = from i in infosList
                          group i by i.Code into g
                          where g.Count()>1
                          select new {
                              Code=g.Key,
                              Cnt =g.Count(),
                          };
                */
                this.txtResult.Text = string.Empty;
                int cnt = 0;
                foreach (var c in q)
                {
                    cnt++;
                    this.txtResult.Text +="Code: "+ c.Code +"\t,Cnt= "+c.Cnt+ Environment.NewLine;
                }
                MessageBox.Show("done! Total:"+cnt.ToString());
                
    
  • 相关阅读:
    移动web开发之flex布局(弹性布局)
    移动web开发之流式布局
    移动端基础
    3D变形(CSS3) transform
    动画(CSS3) animation
    2D变形(CSS3) transform
    过渡(CSS3)
    CSS精灵技术(sprite)
    字体图标
    伸缩布局(CSS3)
  • 原文地址:https://www.cnblogs.com/wucg/p/2041092.html
Copyright © 2011-2022 走看看