keyvaluepair_Dictionary及KeyValuePair使用「建议收藏」

keyvaluepair_Dictionary及KeyValuePair使用「建议收藏」//////除去数组中的空值和签名参数并以字母a到z的顺序排序//////过滤前的参数组///过滤后的参数组publicstaticDictionaryFilterPara(SortedDictionarydicArrayPre){DictionarydicArray=newDictionary();foreach(KeyValuePairtempindicArrayP…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

///

///除去数组中的空值和签名参数并以字母a到z的顺序排序///

/// 过滤前的参数组

/// 过滤后的参数组

public static Dictionary FilterPara(SortedDictionarydicArrayPre)

{

Dictionary dicArray = new Dictionary();foreach (KeyValuePair temp indicArrayPre)

{if (temp.Key.ToLower() != “sign” && temp.Key.ToLower() != “sign_type” && temp.Value != “” && temp.Value != null)

{

dicArray.Add(temp.Key, temp.Value);

}

}returndicArray;

}

///

///把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串///

/// 需要拼接的数组

/// 拼接完成以后的字符串

public static string CreateLinkString(DictionarydicArray)

{

StringBuilder prestr= newStringBuilder();foreach (KeyValuePair temp indicArray)

{

prestr.Append(temp.Key+ “=” + temp.Value + “&”);

}//去掉最後一個&字符

int nLen =prestr.Length;

prestr.Remove(nLen- 1, 1);returnprestr.ToString();

}

///

///把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对参数值做urlencode///

/// 需要拼接的数组

/// 字符编码

/// 拼接完成以后的字符串

public static string CreateLinkStringUrlencode(DictionarydicArray, Encoding code)

{

StringBuilder prestr= newStringBuilder();foreach (KeyValuePair temp indicArray)

{

prestr.Append(temp.Key+ “=” + HttpUtility.UrlEncode(temp.Value, code) + “&”);

}//去掉最後一個&字符

int nLen =prestr.Length;

prestr.Remove(nLen- 1, 1);returnprestr.ToString();

}

C# get keys and values from List

private List> KV_List = new List>();voidinitList()

{

KV_List.Add(new KeyValuePair(“qwer”, “asdf”));

KV_List.Add(new KeyValuePair(“qwer”, “ghjk”));

KV_List.Add(new KeyValuePair(“zxcv”, “asdf”));

KV_List.Add(new KeyValuePair(“hjkl”, “uiop”));

}

//#1: get all keys (remove Distinct() if you don’t want it)

List allKeys = (from kvp in KV_List selectkvp.Key).Distinct().ToList();//allKeys = { “qwer”, “zxcv”, “hjkl” }//#2: get values for a key

string key = “qwer”;

List values = (from kvp in KV_List where kvp.Key == key selectkvp.Value).ToList();//values = { “asdf”, “ghjk” }//#3: get keys for a value

string value = “asdf”;

List keys = (from kvp in KV_List where kvp.Value == value selectkvp.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> kvpList = new List>()

{new KeyValuePair(“Key1”, “Value1”),new KeyValuePair(“Key2”, “Value2”),new KeyValuePair(“Key3”, “Value3”),

};

kvpList.Insert(0, new KeyValuePair(“New Key 1”, “New Value 1”));

foreach (KeyValuePair kvp inkvpList)

{

Console.WriteLine(string.Format(“Key: {0} Value: {1}”, kvp.Key, kvp.Value);

}

Dictionary dicShiftDailys = new Dictionary();

dicShiftDailys = (from entry in dicShiftDailys

orderby entry.Key ascending

select entry).ToDictionary(pair => pair.Key, pair => pair.Value)

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/158800.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • mysql数据库安装(详细)

    mysql数据库安装(详细)安装MySQLMySQL是目前最为流行的开放源码的数据库,是完全网络化的跨平台的关系型数据库系统,它是由瑞典MySQLAB公司开发,目前属于Oracle公司。任何人都能从Internet下载MySQL软件,而无需支付任费用,并且“开放源码”意味着任何人都可以使用和修改该软件。一、下载MySQL第一步:下载mysql,地址:https://dev.mysql.com/downloads/installer/mysql官网上提供了两种安装方式,第一种是在线版联网安装,第二种是本地安装。二者的区别是前者是

    2022年5月11日
    38
  • navicat 1146错误「建议收藏」

    navicat 1146错误「建议收藏」打开新安装的navicat后,有个test_3306的mysql连接,里面有写默认的mysql、information_schema、sys、performance_schema数据库,我以为这是没用的就删除了,之后建立自己的mysql连接后,打开连接报错1146-Table’historyhistoryperformance_schema.session_status’doesn’texist。查阅资料后了解mysql、information_schema、sys、performance_s

    2022年6月7日
    182
  • 如火热链接到css,用于在Webpack中启用热式样装入器以同步css的配置

    如火热链接到css,用于在Webpack中启用热式样装入器以同步css的配置

    2021年8月16日
    53
  • Java反射 Class类常用方法详解

    Java反射 Class类常用方法详解1.返回Class类对应的实体类的相关的Class类的方法:如果我们已经有了一个类的Class类,可以使用下面的一些方法来获得它相关的类:(1)返回当前Class类对应的实体类的父类的Class类:publicClass<?superT>getSuperclass()例如:publicstaticvoidmain(String[]args)throwsClassN…

    2022年5月27日
    41
  • margin重叠的情况和解决_margin重叠导致出现什么效果

    margin重叠的情况和解决_margin重叠导致出现什么效果margin重叠的原因及解决办法

    2022年4月21日
    44
  • linux的文件名的长度限制_linux补全文件名

    linux的文件名的长度限制_linux补全文件名linux下文件数、目录数、文件名长度的各种限制一、文档目的编写本文档,主要目的是为了验证linux下文件数、目录数、文件名长度的各种限制二、文档内容以下测试都是在没有优化或修改内核的前提下测试的结果1.ext3文件系统下filename最大字符长度测试目的:ext3文件系统下filename最大字符长度测试平台:CENTOS5.4_32测试过程:LENTH=`foriin{1..255}…

    2022年10月21日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号