C#中Linq查詢List與DataTable和Dictionary


 

查詢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("全部")) ;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM