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
  • 相关阅读:
    CCDictionary 用调试器查看问题
    博客 小记
    cocos2d-x 调试问题
    string知识
    静动态库
    fedora 20安装vim Transaction check error
    PyQt中ui编译成窗体.py,中文乱码
    centos编译安装vim7.4
    linux c驴杂记
    c++指针 c指针 改变值
  • 原文地址:https://www.cnblogs.com/refuge/p/8150696.html
Copyright © 2011-2022 走看看