• C#中Linq查询List与DataTable和Dictionary be


    查询DataTable返回List

     List<string> listNation = dtNation.AsEnumerable().Select(d => d.Field<string>("MZMC").Trim()).Distinct().ToList();

    查询DataTable返回string

     string strB = (from DataRow r in dtA.Rows
                                  where r.Field<string>("A") == "1034"
                                  select r.Field<string>("B")).FirstOrDefault();

    查询DataTable返回DataTable

    DataTable dtB= (from r in dtA.AsEnumerable()
                           where r.Field<string>("XY").Trim().Equals("A")
                           select r).CopyToDataTable<DataRow>();

    查询List返回Dictionary

    Dictionary<string, string> DictionaryB = ListA.FeeSubject.Where(x => !string.IsNullOrEmpty(x.Code)).Select(x => new { Key = x.FeeCode, Value = x.Code }).Distinct().ToDictionary(c => c.Key, c => c.Value);

    List集合取差集

     List<string > C = A.Except(B).ToList();

     移除

    ComboBoxPar.VmCommun.RemoveAll(x => x.CommunityName.Equals("全部")) ;
  • 相关阅读:
    接水问题
    几种走法
    过河卒

    计数问题
    Java和C或C++的数据类型对照表
    记一次在家办公远程公司数据库的解决方案
    java nio 笔记
    mysql绿色版安装 遇到的问题
    mysql绿色版安装
  • 原文地址:https://www.cnblogs.com/CityOfThousandFires/p/13267937.html
Copyright © 2020-2023  润新知