最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
LINQ生成XML格式数据与C#序列化成XML实例
时间:2013-11-07 编辑:简简单单 来源:一聚教程网
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
|
-
上一个: C#采集网站页面的所有图片与标题内容
相关文章
- C#复制数组的两种方式及效率比较解读 10-24
- ASP.NET Identity用法解析 10-24
- ASP.NET MVC使用Identity增删改查用户介绍 10-24
- C语言中atoi函数模拟实现介绍 10-18
- .Net反向代理组件Yarp用法介绍 10-10
- .NET使用YARP通过编码方式配置域名转发实现反向代理教程 10-10