/// <summary>
/// 除去数组中的空值和签名参数并以字母a到z的顺序排序
/// </summary>
/// <param name="dicArrayPre">过滤前的参数组</param>
/// <returns>过滤后的参数组</returns>
public static Dictionary<string, string> FilterPara(SortedDictionary<string, string> dicArrayPre)
{
Dictionary<string, string> dicArray = new Dictionary<string, string>();
foreach (KeyValuePair<string, string> temp in dicArrayPre)
{
if (temp.Key.ToLower() != "sign" && temp.Key.ToLower() != "sign_type" && temp.Value != "" && temp.Value != null)
{
dicArray.Add(temp.Key, temp.Value);
}
} return dicArray;
}
        /// <summary>
/// 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
/// </summary>
/// <param name="sArray">需要拼接的数组</param>
/// <returns>拼接完成以后的字符串</returns>
public static string CreateLinkString(Dictionary<string, string> dicArray)
{
StringBuilder prestr = new StringBuilder();
foreach (KeyValuePair<string, string> temp in dicArray)
{
prestr.Append(temp.Key + "=" + temp.Value + "&");
} //去掉最後一個&字符
int nLen = prestr.Length;
prestr.Remove(nLen - , ); return prestr.ToString();
}
        /// <summary>
/// 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对参数值做urlencode
/// </summary>
/// <param name="sArray">需要拼接的数组</param>
/// <param name="code">字符编码</param>
/// <returns>拼接完成以后的字符串</returns>
public static string CreateLinkStringUrlencode(Dictionary<string, string> dicArray, Encoding code)
{
StringBuilder prestr = new StringBuilder();
foreach (KeyValuePair<string, string> temp in dicArray)
{
prestr.Append(temp.Key + "=" + HttpUtility.UrlEncode(temp.Value, code) + "&");
} //去掉最後一個&字符
int nLen = prestr.Length;
prestr.Remove(nLen - , ); return prestr.ToString();
}

C# get keys and values from List<KeyValuePair<string, string>

    private List<KeyValuePair<string, string>> KV_List = new List<KeyValuePair<string, string>>();
void initList()
{
KV_List.Add(new KeyValuePair<string, string>("qwer", "asdf"));
KV_List.Add(new KeyValuePair<string, string>("qwer", "ghjk"));
KV_List.Add(new KeyValuePair<string, string>("zxcv", "asdf"));
KV_List.Add(new KeyValuePair<string, string>("hjkl", "uiop"));
}
// #1: get all keys (remove Distinct() if you don't want it)
List<string> allKeys = (from kvp in KV_List select kvp.Key).Distinct().ToList();
// allKeys = { "qwer", "zxcv", "hjkl" } // #2: get values for a key
string key = "qwer";
List<string> values = (from kvp in KV_List where kvp.Key == key select kvp.Value).ToList();
// values = { "asdf", "ghjk" } // #3: get keys for a value
string value = "asdf";
List<string> keys = (from kvp in KV_List where kvp.Value == value select kvp.Key).ToList();
// keys = { "qwer", "zxcv" }

https://stackoverflow.com/questions/31414429/c-sharp-get-keys-and-values-from-listkeyvaluepairstring-string

How to insert an item into a key/value pair object?

List<KeyValuePair<string, string>> kvpList = new List<KeyValuePair<string, string>>()
{
new KeyValuePair<string, string>("Key1", "Value1"),
new KeyValuePair<string, string>("Key2", "Value2"),
new KeyValuePair<string, string>("Key3", "Value3"),
}; kvpList.Insert(, new KeyValuePair<string, string>("New Key 1", "New Value 1"));
foreach (KeyValuePair<string, string> kvp in kvpList)
{
Console.WriteLine(string.Format("Key: {0} Value: {1}", kvp.Key, kvp.Value);
}

Dictionary使用的更多相关文章

  1. C#数组,List,Dictionary的相互转换

    本篇文章会向大家实例讲述以下内容: 将数组转换为List 将List转换为数组 将数组转换为Dictionary 将Dictionary 转换为数组 将List转换为Dictionary 将Dicti ...

  2. ASP.NET Aries JSAPI 文档说明:AR.DataGrid、AR.Dictionary

    AR.Global 文档 1:对象或属性: 名称 类型 说明 DG 对象 DataGrid操作对象 //datagrid集合,根据ID取出DataGrid对象,将Json当数组用. Items: ne ...

  3. WebAPI接口返回ArrayList包含Dictionary对象正确解析

    一.问题提出 为了减少流量,将key-value(键值对)直接输出到Dictionary<string, string>,接口返回结果如下: 其中{}里面内容如下: 上图显示600是键,4 ...

  4. Linq在Array,List,Dictionary中的应用

    Linq在Array,List,Dictionary中的应用 今天在实际工作中需要对array,list,dictionary进行排序,试一试linq,发现非常好用,代码如下: using Syste ...

  5. python之最强王者(8)——字典(dictionary)

    1.Python 字典(Dictionary) 字典是另一种可变容器模型,且可存储任意类型对象. 字典的每个键值(key=>value)对用冒号(:)分割,每个对之间用逗号(,)分割,整个字典包 ...

  6. Swift3 - String 字符串、Array 数组、Dictionary 字典的使用

    Swift相关知识,本随笔为 字符串.数组.字典的简单使用,有理解.使用错误的地方望能指正. ///************************************************** ...

  7. [LeetCode] Alien Dictionary 另类字典

    There is a new alien language which uses the latin alphabet. However, the order among letters are un ...

  8. Dictionary

    命名空间:System.Collections.Generic(程序集:mscorlib) Dictionary<TKey, TValue> 类   一般用法:通过key获取value,k ...

  9. 关于 Dictionary<string,string>,和List<T>在View的使用

    在MVC中Dictionary<string,string>如何应用到View页面中呢,例: <input type="text" name=key value= ...

  10. Dictionary Learning(字典学习、稀疏表示以及其他)

    第一部分 字典学习以及稀疏表示的概要 字典学习(Dictionary Learning)和稀疏表示(Sparse Representation)在学术界的正式称谓应该是稀疏字典学习(Sparse Di ...

随机推荐

  1. sublime学习

    1:goto anything 特性 快捷键  ctrl + P    @  : # 使用 2:多行游标功能 快捷键 ctrl + D     ctrl + K 跳过选择 alt + F3 多选 产生 ...

  2. FileOutputFormat

    TextOutputFormat<K,V> 默认输出字符串输出格式: SequenceFileOutputFormat<K,V> 序列化文件输出: MultipleOutput ...

  3. gnuplot Python API

    源文件 #!/usr/bin/env python from os import popen class gnuplot_leon: # Author : Leon Email: yangli0534 ...

  4. 怎么学习计算电磁学【QUORA】

    链接 There are several resources. But it depends on what you actually want to learn...Let me explain: ...

  5. 双向广搜 POJ 3126 Prime Path

      POJ 3126  Prime Path Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16204   Accepted ...

  6. 解密TDE加密数据库

    1 找到加密的数据库,new query 2 执行sql 语句:ALTER DATABASE  database_name SET ENCRYPTION OFF; DROP DATABASE ENCR ...

  7. 第2章 面向对象的设计原则(SOLID):4_接口隔离原则(ISP)

    4. 接口隔离原则(Interface Segregation Principle,ISP) 4.1 定义 (1)使用多个专门的接口,而不使用单一的总接口,即客户端不应该依赖那些它不需要的接口.类间的 ...

  8. java11-3 String类的获取功能

    String类的获取功能 int length():获取字符串的长度. char charAt(int index):获取指定索引位置的字符 int indexOf(int ch):返回指定字符在此字 ...

  9. 关于tcpdump抓包一个很详细的介绍

    http://www.cnblogs.com/ggjucheng/archive/2012/01/14/2322659.html

  10. Socurce Insight 快捷键

    1. 高亮当前选中的的 变量 Shift + F8