最新下载
热门教程
- 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
|
相关文章
- 鬼谷八荒手游筑基材料怎么快速获取-鬼谷八荒手游筑基材料怎么刷 08-09
- 燕云十六声辞生无泪任务攻略-燕云十六声辞生无泪任务怎么做 08-09
- 率土之滨如何删除角色-率土之滨删除角色方法一览 08-09
- 崩坏星穹铁道3.0卡池安排-崩坏星穹铁道3.0卡池预测 08-09
- 《燕云十六声》狂澜门派加入攻略 怎么加入狂澜门派 08-09
- 全职荣耀开局球星选择攻略-全职荣耀开局球星怎么选择 08-09