从字典< string,dictionary< string,string>>中删除最后一个字符使用C# [英] Remove last character from dictionary<string, dictionary<string, string>> using C#
本文介绍了从字典< string,dictionary< string,string>>中删除最后一个字符使用C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有
Hi,
I have
Dictionary<string, Dictionary<string, string>>
我的内部字典数据如下所示
My inner dictionary data is shown below
{
"1": {
"message-Code1": " 0",
"msg-Number-Pos11": "0",
"msg-Number-Pos21": "0",
"msg-Number-Pos31": " "
},
"2": {
"message-Code2": " 0",
"msg-Number-Pos12": "0",
"msg-Number-Pos22": "0",
"msg-Number-Pos32": " "
}
如何从每个键中删除最后一个字符,即第一组中的1和第二组中的2。
我尝试过:
How can I remove the last character from every key i.e 1 in the first set and 2 in the second set of result.
What I have tried:
var dicion = dictionary.Where(pair => pair.Value.Remove(pair.Value.Key.Last()));
推荐答案
你好不要从字典的键中删除一个字符。
但是您可以使用修改后的密钥创建一个新条目,并删除具有原始条目的条目。
You cannot remove a character from the key of the dictionary.
However you can create a new entry with the modified key and remove the entry having the original one.
这篇关于从字典< string,dictionary< string,string>>中删除最后一个字符使用C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文