zoukankan      html  css  js  c++  java
  • Linq Aggregate

     IList<Student> studentList = new List<Student>() {
                    new Student() { StudentID = 1, StudentName = "John", StandardID =1 },
                    new Student() { StudentID = 2, StudentName = "Moin", StandardID =1 },
                    new Student() { StudentID = 3, StudentName = "Bill", StandardID =2 },
                    new Student() { StudentID = 4, StudentName = "Ram" , StandardID =2 },
                    new Student() { StudentID = 5, StudentName = "Ron"  }
                };
    
    var tt = studentList.Aggregate("startStr:", (s1, s2) => s1 + s2.StudentName + ",");
    Console.WriteLine(tt);//startStr:John,Moin,Bill,Ram,Ron,
    var tt1 = studentList.Aggregate("startStr:", (s1, s2) => s1 + s2.StudentName + ",",s1=>s1.Substring(0,s1.Length-1));
    Console.WriteLine(tt1);//startStr:John,Moin,Bill,Ram,Ron
    IList<String> strList = new List<String>() { "One", "Two", "Three", "Four", "Five" };
    var str = strList.Aggregate((s1, s2) => s1 + "-" + s2);
    Console.WriteLine(str);//One-Two-Three-Four-Five
    
    //这个方法更优雅
    str = string.Join("-", strList);
    Console.WriteLine(str);//One-Two-Three-Four-Five
  • 相关阅读:
    ubuntu安装后要做什么
    JavaScript错误处理
    jQuery 事件
    display的用法
    百度排名的原理
    什么是ajax?
    CSS文档流
    引用CSS的方法
    jQuery的安装方式
    禁止WPS2019开机自启动
  • 原文地址:https://www.cnblogs.com/refuge/p/8150696.html
Copyright © 2011-2022 走看看