欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C#教程

當前位置:主頁 > 軟件編程 > C#教程 >

C#中查找Dictionary中的重復值的方法

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C#教程|點擊: 次

在這篇幫助文檔中,我將向你展示如何實現(xiàn)c#里字典中重復值的查找。你知道的對于一個老鳥來說,這是非常簡單的代碼。但是盡管如此,這也是一篇對c#初學者非常有用的幫助文檔。
背景:多數(shù)程序員對小型數(shù)據(jù)源存儲的處理方式通常是創(chuàng)建字典進行鍵值存儲。主鍵時唯一的,但是字典值卻可能有重復的元素。
代碼如下

//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("dictionary elements........ www.jb51.net <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 />dictionary duplicate values..........<br />");
 
//loop dictionary duplicate values only      
foreach(var item in duplicateValues) 
{
  Response.Write(item.Key+"<br />");
}

 以上就是我使用一個簡單的LINQ語句來查找字典中的重復值,大家可以嘗試實驗一下。

上一篇:C#實現(xiàn)3步手動建DataGridView的方法

欄    目:C#教程

下一篇:c# ArrayList的使用方法小總結(jié)

本文標題:C#中查找Dictionary中的重復值的方法

本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/6994.html

網(wǎng)頁制作CMS教程網(wǎng)絡編程軟件編程腳本語言數(shù)據(jù)庫服務器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進行處理、任何非本站因素導致的法律后果,本站均不負任何責任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有