在這篇贊助文檔中,我將向你展現若何完成C#裡字典中反復值的查找。你曉得的關於一個老鳥來講,這長短常簡略的代碼。然則雖然如斯,這也是一篇對C#初學者異常有效的贊助文檔。
配景:多半法式員對小型數據源存儲的處置方法平日是創立字典停止鍵值存儲。主鍵時獨一的,然則字典值卻能夠有反復的元素。
代碼以下
//initialize a dictionary with keys and values. Dictionary<int, string> plants = new Dictionary<int, string>() { {1,"Speckled Alder"}, {2,"Apple of Sodom"}, {3,"Hairy Bittercress"}, {4,"Pennsylvania Blackberry"}, {5,"Apple of Sodom"}, {6,"Water Birch"}, {7,"Meadow Cabbage"}, {8,"Water Birch"} }; Response.Write("<b>dictionary elements........ www.jb51.net </b><br />"); //loop dictionary all elements foreach (KeyValuePair<int, string> pair in plants) { Response.Write(pair.Key + "....."+ pair.Value+"<br />"); } //find dictionary duplicate values. var duplicateValues = plants.GroupBy(x => x.Value).Where(x => x.Count() > 1); Response.Write("<br /><b>dictionary duplicate values..........</b><br />"); //loop dictionary duplicate values only foreach(var item in duplicateValues) { Response.Write(item.Key+"<br />"); }
以上就是我應用一個簡略的LINQ語句來查找字典中的反復值,年夜家可以測驗考試試驗一下。
【詳解iOS中UIButton的三年夜UIEdgeInsets屬性用法】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!