zoukankan      html  css  js  c++  java
  • List对象中的组合、查询、扩展

    var Pnts = segs.Select( c =>
                                                 pntTsLst.Where                                                            //根据条件组合另一个List, pntTsLst是一个List<KEYPOINT>
                                                 (d => d.KEYPOINT_UUID == c.END_POINT_ID)
                                                                                                                              .Select(
                                                                                                                                               k =>new { id=k.KEYPOINT_UUID,name=k.NAME + (k.DESIGNATOR.IsEmptyOrNull() ? "" : $"({k.DESIGNATOR})"),seq=c.SEQNUM+1 }  //从另一个List中取值并添加其他属性
                                                                                                                                          ).First()      //First非常重要,作用于where,把整个最外层括号中的数据类型变为属性,否则是个两重List结构                            
                                                 ).ToList();

    //Pnts 是一个自定义对象{id,name,seq} 的list

    //简单一点List转换的例子 Geoms是一个Geom(id,name,geo)的对象list

     Geoms = dic.Select(c => new Geom{ id=c.Key,geo=c.Value} ).ToList();

    或者,返回一个扩展的对象

    var lst = Pnts.Select(c => new {
                                                          keypt =pntTsLst.Where(d => d.KEYPOINT_UUID == c.id).First(),
                                                          seq =c.seq
                                                     }

                                     ).ToList();

    lst 是一个扩展对象{KEYPOINT,seq}的list

  • 相关阅读:
    JQuery文档插件
    MVC3下使用Jquery异步提交数据!
    不错的在线客服插件~
    让火狐和chorme浏览器支持uploadify带Cookie上传
    Socket服务器代码
    Winform控件加载时闪烁的解决方案!
    MVC3 无刷新验证码
    网络时间同步
    关于多线程委托的控件操作
    c# 利用反射动态给实体类对象赋值
  • 原文地址:https://www.cnblogs.com/mol1995/p/8275497.html
Copyright © 2011-2022 走看看