LINQ操作List<T>
2015-07-20 14:12
295 查看
LINQ操作List<T>主要包括:
1.筛选
2.拼接
3.分组统计
4.分组拼接
1.筛选
List<string> stcdList = stcdArray.ToList<string>() .FindAll(new Predicate<string>(stcd => stcd.Contains("stcd_"))) .Select(stcd => stcd.Substring(5)) .ToList<string>();
2.拼接
List<string> suggestion = new List<string>(); string sg_font_details = suggestion.Aggregate((s1, s2) => string.Format("{0},{1}", s1, s2)).ToString();
3.分组统计
public class HomeStat { public string adnm { get; set; } public string ProCount { get; set; } public string countCompare { get; set; } public string perCount { get; set; } public string dayCount { get; set; } public string perDayCount { get; set; } } List<HomeStat> chsList = new List<HomeStat>() {... }; var query = hsList.GroupBy(t => t.adnm).Select(p => new { adnm = p.Key, dayCount = p.Sum(x => double.Parse(x.dayCount)), proCount = p.Select(x => x.projectID).Distinct().Count(), perCount = p.Sum(x => double.Parse(x.perCount)), perDayCount = p.Sum(x => double.Parse(x.perDayCount)) });
4.分组拼接
public class Service { public string Month { get; set; } public string Content { get; set; } } List<Service> serList = new List<Service>(){...}; var query = serList.GroupBy(t => t.Month).Select(g => g.Aggregate((s1, s2) => new Service { Month = g.Key, Content = s1.Content + "," + s2.Content })) .OrderByDescending(t => t.Month);
相关文章推荐
- Android.mk 文件语法大全
- 黑马程序员-----Java基础
- 文件的下载
- JSON 数据结构介绍
- 蓝光基本术语
- 国外的php mcv框架
- spring的annotation-driven配置事务管理器详解
- C#/ASP.NET MVC微信公众号接口开发之从零开发(三)回复消息 (附源码)
- 跨域一
- 表单内容提交到数据库案例
- 【VBS】发邮件
- 二分查找
- 面试官最爱提的问题TOP10来自:北京人才市场报
- 在Linux中如何安装gcc
- 简单倒计时实现
- POJ 3279(Fliptile)题解
- centos6.5更改为163的yum源
- SrollView中嵌套GridView冲突
- 装箱问题
- CRM实施中应避免的5大问题