码迷,mamicode.com
首页 > Windows程序 > 详细

C#将Dictionary转换为XML

时间:2016-04-19 19:07:31      阅读:2370      评论:0      收藏:0      [点我收藏+]

标签:


Dictionary to Element:

Dictionary<string, string> dict = new Dictionary<string,string>();
XElement el = new XElement("root",
dict.Select(kv => new XElement(kv.Key, kv.Value)));


Element to Dictionary:

XElement rootElement = XElement.Parse("<root><key>value</key></root>");
Dictionary<string, string> dict = new Dictionary<string, string>();
foreach(var el in rootElement.Elements())
{
dict.Add(el.Name.LocalName, el.Value);
}

 

you can use ToDictionary... rootElement.Elements().ToDictionary( key => key.Name, val => val.Value);

C#将Dictionary转换为XML

标签:

原文地址:http://www.cnblogs.com/mapley/p/5409138.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!