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
  • 相关阅读:
    3.5.3 数据排序;重复数值、缺失值处理
    3.5.1 pandas基础
    3.3 numpy
    数据准备和特征工程
    2.4函数
    2.3语句与控制流
    2.2数据结构与序列
    2.1Python基础知识
    五、MySQL安装
    四、Hadoop HA 集群搭建
  • 原文地址:https://www.cnblogs.com/refuge/p/8150696.html
Copyright © 2011-2022 走看看