zoukankan      html  css  js  c++  java
  • Linq to List

    var lstMater = lst.GroupBy(w => new { w.materialId, w.name, w.isPass, w.description }).
    Select(g =>
    new View_El_MyCourse_MaterialInfo
    {
    description = g.Key.description,
    isPass = g.Key.isPass,
    materialId = g.Key.materialId,
    name = g.Key.name
    }).OrderBy(w => w.sortId).ToList();

    foreach (var item in lstMater)
    {
    View_El_MyCourse_MaterialInfo o = new View_El_MyCourse_MaterialInfo();
    o.courseId = item.courseId;
    o.description = item.description;
    o.materialId = item.materialId;
    }

    写Linq to List时,当需要分组的时候,需要将你所有需要的值,都需要写上,相当于你默认构造一个匿名类,一个载体,然后在select中 再将值赋值回去

    这样你就可以在下面操作集合的时候,自动跟随出你想要的东西。

    此中,lst为集合对象。

    这只是我个人今天遇到问题的解决方法,若有理解错误的地方,请大家留言指点。

  • 相关阅读:
    JSON和Object数组在js中的转换
    Raphael绘制箭头arrow
    Web后台框架开发
    数据库开发
    docker
    git
    linux
    正则表达式工具
    python模拟ls命令
    python3基础
  • 原文地址:https://www.cnblogs.com/it1042290135/p/6399361.html
Copyright © 2011-2022 走看看