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的更多相关文章

  1. C# Dictionary通过value获取对应的key值

    1:最直白的循环遍历方法,可以分为遍历key--value键值对以及所有的key两种表现形式 2:用Linq的方式去查询(当然了这里要添加对应的命名空间 using System.Linq) 如下为一 ...

  2. C# Dictionary通过value获取对应的key值[转发]

    1:最直白的循环遍历方法,可以分为遍历key--value键值对以及所有的key两种表现形式 2:用Linq的方式去查询(当然了这里要添加对应的命名空间 using System.Linq) 如下为一 ...

  3. Dictionary里使用struct,enum做key

    首先看下Dictionary的源码 public void Add (TKey key, TValue value) { if (key == null) throw new ArgumentNull ...

  4. Dictionary——通过value找Key

    Dictionary<string, string> dic = GetRoleDescriptions(); string key = dic.FirstOrDefault(x => ...

  5. C#创建安全的字典(Dictionary)存储结构

    在上面介绍过栈(Stack)的存储结构,接下来介绍另一种存储结构字典(Dictionary). 字典(Dictionary)里面的每一个元素都是一个键值对(由二个元素组成:键和值) 键必须是唯一的,而 ...

  6. .net源码分析 – Dictionary<TKey, TValue>

    接上篇:.net源码分析 – List<T> Dictionary<TKey, TValue>源码地址:https://github.com/dotnet/corefx/blo ...

  7. .NET中Dictionary<TKey, TValue>浅析

    .NET中Dictionary<TKey, Tvalue>是非常常用的key-value的数据结构,也就是其实就是传说中的哈希表..NET中还有一个叫做Hashtable的类型,两个类型都 ...

  8. C#中字典集合HashTable、Dictionary、ConcurrentDictionary三者区别

    C#中HashTable.Dictionary.ConcurrentDictionar三者都表示键/值对的集合,但是到底有什么区别,下面详细介绍 一.HashTable HashTable表示键/值对 ...

  9. 字典集合Dictionary<K,V>和构造的应用==>>体检套餐项目

    效果 首先,我们先来准备我们需要的类 1.检查项目类 using System; using System.Collections.Generic; using System.Linq; using ...

随机推荐

  1. python 基础干货 01

    赋值的实现 a = 'abc' 1. 在内存中创建了'abc'字符串; 2. 在内存中创建了一个名为 a 的变量, 并把它指向刚才创建的'abc', 也就是a中保存着字符串的地址. b = a, 创建 ...

  2. SSKeyChains的使用小节

    我是前言: 最近在项目中需要使用钥匙串来进行账户密码的保存,小结一下.贴上框架地址:https://github.com/soffes/SAMKeychain. 它提供了5个类方法使用: + (NSA ...

  3. 对tomcat来说,每一个进来的请求(request)都需要一个线程,直到该请求结束。

    这段时间折腾了哈java web应用的压力测试,部署容器是tomcat 7.期间学到了蛮多散碎的知识点,及时梳理总结,构建良好且易理解的知识架构把它们组织起来,以备忘.对web应用开发者来说,我们很关 ...

  4. Cocos2d-js 3.0 alp2 使用指南

    Download Cocos2d-JS: http://www.cocos2d-x.org/download Unzip and copy to C:/ Download JDK: http://ww ...

  5. DragQueryFile

    附件:http://files.cnblogs.com/xe2011/CSharp_DragQueryFile.rar using System.Runtime.InteropServices; th ...

  6. [Redux] Colocating Selectors with Reducers

    We will learn how to encapsulate the knowledge about the state shape in the reducer files, so that t ...

  7. 用C语言扩展Python的功能

    https://www.ibm.com/developerworks/cn/linux/l-pythc/

  8. careercup-链表 2.6

    2.6 给定一个有环链表,实现一个算法返回环路的开头结点. 类似leetcode中 Linked List Cycle II C++实现代码: #include<iostream> #in ...

  9. j2ee学习笔记URLEncoder.encode(String , enc)处理特殊字符

    从页面上传递数据时,特殊字符对于超链接会自动进行解码 : 其他方式需要手动进行解码.

  10. Javascript 异步编程的4种方法详解

    你可能知道,Javascript语言的执行环境是"单线程"(single thread). 所谓"单线程",就是指一次只能完成一件任务.如果有多个任务,就必须排 ...