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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • yarn安装依赖失败_yarn

    yarn安装依赖失败_yarnnpm安装yarn成功但无法使用的问题

    2022年9月1日
    4
  • BZOJ 2588 Count on a tree (COT) 是持久的段树

    BZOJ 2588 Count on a tree (COT) 是持久的段树

    2022年1月5日
    47
  • vue cil安装axios

    vue cil安装axiosVuecil安装axios1、安装axioscnpminstallaxios如果没有安装cnpm的可能安装不成功,这里列出安装cnpm,使用淘宝镜像。npminstall-gcnpm–registry=https://registry.npm.taobao.org2、使用方法2.1、首先在main.js配importaxiosfrom”axiosVue.prototype.$axios=axios好了就可以在项目中使用axios了。…

    2025年6月19日
    2
  • 【STM32】HAL库 STM32CubeMX教程十二—IIC(读取AT24C02 )

    【STM32】HAL库 STM32CubeMX教程十二—IIC(读取AT24C02 )IIC简介IIC(Inter-IntegratedCircuit)总线是一种由NXP(原PHILIPS)公司开发的两线式串行总线,用于连接微控制器及其外围设备。多用于主控制器和从器件间的主从通信,在小数据量场合使用,传输距离短,任意时刻只能有一个主机等特性。在CPU与被控IC之间、IC与IC之间进行双向传送,高速IIC总线一般可达400kbps以上。PS:这里要注…

    2022年6月8日
    60
  • 教你win10系统显卡驱动安装失败的解决方法

    教你win10系统显卡驱动安装失败的解决方法我们日常在对电脑的使用过程中,经常都会遇到这样或那样的问题。比如说win10系统显卡驱动安装失败该怎么办呢?别着急,还有小编在呢?接下来小编就来告诉大家win10电脑系统显卡驱动安装失败怎么解决。详细教你win10系统显卡驱动安装失败怎么办:方法一,删除之前的显卡驱动文件重新安装1,首先,右键点击“此电脑”,菜单栏选择“管理”。2,进入计算机管理界面后,点击“设备管理器”,然后在界面右侧展开“显示适配器”选项,并右键点击显卡驱动程序,菜单栏选择“属性”下一步。3,点击“卸载设备”。4,显卡

    2022年6月13日
    33
  • vue跨域解决的几种方案「建议收藏」

    vue跨域解决的几种方案「建议收藏」vue跨域解决的几种方案一、开发环境解决跨域方法平时使用vue开发的时候,大多会使用vue-cli搭建项目,在vue-cli搭建的项目中有一个配置文件vue.config.js,可以在该文件中进行相应的配置解决开发环境的跨域问题。第一步设置公共urlapi/index.jsimportaxiosfrom’axios’importrouterfrom’@/router/index.js’importstorefrom’@/store/index.js’//创建一个axios

    2022年10月1日
    2

发表回复

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

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