jjzjj

c# - 在 C# 中向字典添加数据

我有一个类似的xml文件和字典Dictionary>m_dictSample=newDictionary>();我需要将文件中的数据添加到字典中,例如:KeyOne"1""2""3""4"KeyTwo"5""6"KeyThree"7""8""9""10"现在我正在使用likeListlst=newList();lst=(XDocument.Load(Application.StartupPath+"\\Sample.xml").Descendants("Element").Select(l_Temp=>l_Temp.Attribute("Key").Value)).ToList();m

c# - C#中如何向字典中添加数据

如何从xml文件中向字典添加数据场景:我已经声明了一个字典DictonarySampleDict=newDictonary();我的xml文件是这样的我需要使用LINQ读取“ValOne”和“ValTwo”的值并将其插入到上面声明的字典中以及如何将字典的内容添加到包含两列的ListView。请帮我做这个提前致谢 最佳答案 您可以为此使用LinqtoXML和ToDictionary。vardoc=XDocument.Load("pathtoxml");doc.Elements("Element").ToDictionary(elem=