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

  • 相关阅读:
    解决C#程序只允许运行一个实例的几种方法详解
    C# static const和readonly区别
    c# string.format和tostring()
    DataTable与实体类互相转换
    java switch语句 要点注意
    java 运算符&表达式
    java数据类型(大小等),变量定义,各进制书写方法
    Java标识符(Identifier)(关键字和保留字)
    关于美剧《越狱》
    一些四六级的事
  • 原文地址:https://www.cnblogs.com/mol1995/p/8275497.html
Copyright © 2011-2022 走看看