最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
LINQ生成XML格式数据与C#序列化成XML实例
时间:2022-06-25 08:16:29 编辑:袖梨 来源:一聚教程网
LINQ生成XML格式数据
代码如下 | 复制代码 |
using System.Xml.Linq; static void Main(string[] args) { //LINQ生成XML格式的数据,相比较把对象序列化成XML文件要灵活性好点using System.Xml.Linq; List { new Student{ID=1,Name="林书豪",Scores=new List new Student{ID=1,Name="张三丰",Scores=new List }; var xml = new XElement("Root", from l in list let x = String.Format("{0},{1},{2}", l.Scores[0], l.Scores[1], l.Scores[2]) select new XElement("Student", new XElement("ID", l.ID), new XElement("Name", l.Name), new XElement("Scores", x) ) ); Console.Write(xml); Console.Read(); /* */ } class Student { public int ID { get; set; } public string Name { get; set; } public List } |
序列化成XML文件
对象序列化成XML
代码如下 | 复制代码 |
using System.Xml.Serialization; StreamWriter file = new StreamWriter(Server.MapPath("product.xml")); public class Product
|
相关文章
- 《职场浮生记》卡牌模组推荐 06-15
- 《纸嫁衣4红丝缠》全章节图文攻略 06-15
- 《这城有良田》奖率三军课业加点攻略 06-15
- 《纸嫁衣2奘铃村》全章节攻略汇总 06-15
- 《王者荣耀》夺宝保底次数介绍 06-15
- 《向僵尸开炮》百分比宝石选择推荐 06-15