1:循环遍历法,分为遍历key-value键值对和遍历所有key两种形式

2:使用Linq查询法

     private void GetDictKeyByValue()
{
Dictionary<int, string> dict = new Dictionary<int, string>();
dict.Add(, "");
dict.Add(, "");
dict.Add(, "");
dict.Add(, ""); // foreach KeyValuePair
List<int> list = new List<int>();
foreach (KeyValuePair<int, string> kvp in dict)
{
if (kvp.Value.Equals(""))
{
list.Add(kvp.Key); // kvp.Key;
}
} // foreach dic.Keys
list.Clear();
foreach (int key in dict.Keys)
{
if (dict[key].Equals(""))
{
list.Add(key); // key
}
} // Linq
List<int> keyList = dict.Where(q => q.Value == "")
.Select(q => q.Key).ToList<int>(); //get all keys keyList = (from q in dict
where q.Value == ""
select q.Key).ToList<int>(); //get all keys var firstKey = dict.FirstOrDefault(q => q.Value == "").Key; //get first key
}

C# Dictionary已知value获取对应的key的更多相关文章

  1. 已知起始点,获取每段等距离途经点的经纬度(用百度js api作)

    已知两个中文地址,自动规划路径,获取路径上每个3公里的点的经纬度 <html> <head> <meta http-equiv="Content-Type&qu ...

  2. java基础 File与递归练习 使用文件过滤器筛选将指定文件夹下的小于200K的小文件获取并打印按层次打印(包括所有子文件夹的文件) 多层文件夹情况统计文件和文件夹的数量 统计已知类型的数量 未知类型的数量

    package com.swift.kuozhan; import java.io.File; import java.io.FileFilter; /*使用文件过滤器筛选将指定文件夹下的小于200K ...

  3. Acticiti流程引擎在已知当前流程定义id的情况下获取当前流程的所有信息(包括:节点和连线)

    这里我们已知流程已经部署,我的需求是获取当前流程的所有任务节点,我使用instanceof关键字来进行匹配 private List<UserTask> getProcessUserTas ...

  4. 对象布局已知时 C++ 对象指针的转换时地址调整

    在我调试和研究 netscape 系浏览器插件开发时,注意到了这个问题.即,在对象布局已知(即对象之间具有继承关系)时,不同类型对象的指针进行转换(不管是隐式的从下向上转换,还是强制的从上到下转换)时 ...

  5. Java集合-5. (List)已知有一个Worker 类如下: 完成下面的要求 1) 创建一个List,在List 中增加三个工人,基本信息如下: 姓名 年龄 工资 zhang3 18 3000 li4 25 3500 wang5 22 3200 2) 在li4 之前插入一个工人,信息为:姓名:zhao6,年龄:24,工资3300 3) 删除wang5 的信息 4) 利用for 循

    第六题 5. (List)已知有一个Worker 类如下: public class Worker { private int age; private String name; private do ...

  6. WCF 已知类型和泛型解析程序 KnownType

    数据协定继承 已知类型和泛型解析程序 Juval Lowy 下载代码示例 自首次发布以来,Windows Communication Foundation (WCF) 开发人员便必须处理数据协定继承方 ...

  7. 已知json类型根据类型封装集合

    1编写帮助类根绝url得到json public static string Post(string url) { string strURL = url; //创建一个HTTP请求 HttpWebR ...

  8. HDU - 6096 :String (AC自动机,已知前后缀,匹配单词,弱数据)

    Bob has a dictionary with N words in it. Now there is a list of words in which the middle part of th ...

  9. javascript 解决默认取整的坑(目前已知的最佳解决方案)

    javascript 解决默认取整的坑(目前已知的最佳解决方案) 复现该问题 js在数字操作时总会取更高精度的结果,例如1234/10结果就是123.4,但是在c或者java中整数除以10的结果还是整 ...

随机推荐

  1. poj 2774 Long Long Message 后缀数组基础题

    Time Limit: 4000MS   Memory Limit: 131072K Total Submissions: 24756   Accepted: 10130 Case Time Limi ...

  2. 并查集(图论) LA 3644 X-Plosives

    题目传送门 题意:训练指南P191 分析:本题特殊,n个物品,n种元素则会爆炸,可以转移到图论里的n个点,连一条边表示u,v元素放在一起,如果不出现环,一定是n点,n-1条边,所以如果两个元素在同一个 ...

  3. Oralce 常用语句

    注:大写代表需要替换掉额 --更新字段名 alter table TABLE rename column COL_OLD to COL_NEW --添加字段名 alter table TABLE ad ...

  4. docker不稳定 short running containers with -rm failed to destroy

    正常运行以下命令 sudo docker run --rm busybox echo helloworld /var/log/upstart/docker.log 日志如下: // :: POST / ...

  5. start bbs轻论坛安装时数据库提示错误

    A PHP Error was encounteredSeverity: NoticeMessage: Only variable references should be returned by r ...

  6. oracle视图

    视图 SELECT -- int.rowner "rgroup owner", -- int.rname "refresh group", mv.owner a ...

  7. django 数据库交互

    修改配置文件 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'USER':'root', 'PASSWORD':'1 ...

  8. Codeforces Round #248 (Div. 2) B. Kuriyama Mirai's Stones

    题目简单描述就是求数组中[l,r]区间的和 #include <iostream> #include <vector> #include <string> #inc ...

  9. [CareerCup] 15.4 Types of Join 各种交

    15.4 What are the different types of joins? Please explain how they differ and why certain types are ...

  10. mysql体系结构

    mysql逻辑架构: 第一层,即最上一层,所包含的服务并不是MySQL所独有的技术.它们都是服务于C/S程序或者是这些程序所需要的:连接处理,身份验证,安全性等等. 第二层值得关注.这是MySQL的核 ...