Dictionary通过Value找到它的key
private void GetDicKeyByValue()
{
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("", "");
dic.Add("", "");
dic.Add("", "");
//foreach KeyValuePair traversing
foreach (KeyValuePair<string, string> kvp in dic)
{
if (kvp.Value.Equals(""))
{
//...... kvp.Key;
}
} //foreach dic.Keys
foreach (string key in dic.Keys)
{
if (dic[key].Equals(""))
{
//...... key
}
} //Linq
var keys = dic.Where(q => q.Value == "").Select(q => q.Key); //get all keys List<string> keyList = (from q in dic
where q.Value == ""
select q.Key).ToList<string>(); //get all keys var firstKey = dic.FirstOrDefault(q => q.Value == "").Key; //get first key
}
Dictionary通过Value找到它的key的更多相关文章
- C# Dictionary通过value获取对应的key值
		1:最直白的循环遍历方法,可以分为遍历key--value键值对以及所有的key两种表现形式 2:用Linq的方式去查询(当然了这里要添加对应的命名空间 using System.Linq) 如下为一 ... 
- C# Dictionary通过value获取对应的key值[转发]
		1:最直白的循环遍历方法,可以分为遍历key--value键值对以及所有的key两种表现形式 2:用Linq的方式去查询(当然了这里要添加对应的命名空间 using System.Linq) 如下为一 ... 
- Dictionary里使用struct,enum做key
		首先看下Dictionary的源码 public void Add (TKey key, TValue value) { if (key == null) throw new ArgumentNull ... 
- Dictionary——通过value找Key
		Dictionary<string, string> dic = GetRoleDescriptions(); string key = dic.FirstOrDefault(x => ... 
- C#创建安全的字典(Dictionary)存储结构
		在上面介绍过栈(Stack)的存储结构,接下来介绍另一种存储结构字典(Dictionary). 字典(Dictionary)里面的每一个元素都是一个键值对(由二个元素组成:键和值) 键必须是唯一的,而 ... 
- .net源码分析 – Dictionary<TKey, TValue>
		接上篇:.net源码分析 – List<T> Dictionary<TKey, TValue>源码地址:https://github.com/dotnet/corefx/blo ... 
- .NET中Dictionary<TKey, TValue>浅析
		.NET中Dictionary<TKey, Tvalue>是非常常用的key-value的数据结构,也就是其实就是传说中的哈希表..NET中还有一个叫做Hashtable的类型,两个类型都 ... 
- C#中字典集合HashTable、Dictionary、ConcurrentDictionary三者区别
		C#中HashTable.Dictionary.ConcurrentDictionar三者都表示键/值对的集合,但是到底有什么区别,下面详细介绍 一.HashTable HashTable表示键/值对 ... 
- 字典集合Dictionary<K,V>和构造的应用==>>体检套餐项目
		效果 首先,我们先来准备我们需要的类 1.检查项目类 using System; using System.Collections.Generic; using System.Linq; using ... 
随机推荐
- MySQL执行计划 EXPLAIN参数
			MySQL执行计划参数详解 转http://www.jianshu.com/p/7134286b3a09 MySQL数据库中,在SELECT查询语句前边加上“EXPLAIN”或者“DESC”关键字,即 ... 
- Apache Commons 工具类介绍及简单使用
			转自:http://www.cnblogs.com/younggun/p/3247261.html Apache Commons包含了很多开源的工具,用于解决平时编程经常会遇到的问题,减少重复劳动.下 ... 
- php 燕十八 观察者模式代码例子
			<?php class user implements SplSubject { public $lognum; public $hobby; protected $observers=null ... 
- Android开发之50个常见实用技巧——添加悦目的动画效果
			Hack.5 使用TextSwitcher和ImageSwitcher实现平滑过渡 实现步骤: 1.通过findViewById()方法获取TextSwitcher对象的引用Swithcer,当然也可 ... 
- PHP面试题三
			1.nginx使用哪种网络协议? nginx是应用层 我觉得从下往上的话 传输层用的是tcp/ip 应用层用的是http fastcgi负责调度进程 2. <? echo 'hello tush ... 
- iOS socket小结01
			一.网络各个协议:TCP/IP.SOCKET.HTTP等 网络七层由下往上分别为物理层.数据链路层.网络层.传输层.会话层.表示层和应用层. 其中物理层.数据链路层和网络层通常被称作媒体层,是网络工程 ... 
- SDK更新太慢
			同时,更新ADT和SDK Manager 在SDK Manager下Tools->Options打开了SDK Manager的Settings,选中“Force https://… source ... 
- Python数据类型转换
			Python数据类型之间的转换 函数 描述 int(x [,base]) 将x转换为一个整数 long(x [,base] ) 将x转换为一个长整数 float(x) 将x转换到一个浮点数 compl ... 
- Btrace
			http://www.iteye.com/topic/1005918 背景 周五下班回家,在公司班车上觉得无聊,看了下btrace的源码(自己反编译). 一些关于btrace的基本内容,可以看下我早起 ... 
- jsp-javabean-setproperty介绍
			李兴华<java web开发实战经典>第7章关于javabean的讲解中说道:<jsp:setProperty>标签一共有4种使用方法·下面列出了4种操作语法的格式: 设置 ... 
