static void Main(string[] args)
        {    // Create the data source by using a collection initializer.
            var students = new[]
        {
            new {First="Svetlana", Last="Omelchenko", ID=111, Scores = new List<int>{97, 92, 81, 60}},
            new {First="Claire", Last="O’Donnell", ID=112, Scores = new List<int>{75, 84, 91, 39}},
            new {First="Sven", Last="Mortensen", ID=113, Scores = new List<int>{88, 94, 65, 91}},
        };
 
            // Create the query.
            var studentsToXML = new XElement("Root",
                from student in students
                let x = String.Format("{0},{1},{2},{3}", student.Scores[0],
                        student.Scores[1], student.Scores[2], student.Scores[3])
                select new XElement("student",
                           new XElement("First", student.First),
                           new XElement("Last", student.Last),
                        new XElement("Scores", x)
                        ) // end "student"
                    ); // end "Root"
 
            // Execute the query.
            Console.WriteLine(studentsToXML);
 
            // Keep the console open in debug mode.
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
 
        }
 
运行经结果:
 

C# LINQ to XML示例的更多相关文章

  1. Linq to Xml示例

    Xml文件: <?xml version="1.0"?> <Software xmlns:xsi="http://www.w3.org/2001/XML ...

  2. C# linq to xml 简单示例

    data.xml <?xml version="1.0" encoding="utf-8" ?> <Data> <Products ...

  3. LINQ系列:LINQ to XML类

    LINQ to XML由System.Xml.Linq namespace实现,该namespace包含处理XML时用到的所有类.在使用LINQ to XML时需要添加System.Xml.Linq. ...

  4. LINQ系列:LINQ to XML查询

    1. 读取XML文件 XDocument和XElement类都提供了导入XML文件的Load()方法,可以读取XML文件的内容,并转换为XDocument或XElement类的实例. 示例XML文件: ...

  5. [原创]Linq to xml增删改查Linq 入门篇:分分钟带你遨游Linq to xml的世界

    本文原始作者博客 http://www.cnblogs.com/toutou Linq 入门篇(一):分分钟带你遨游linq to xml的世界 本文原创来自博客园 请叫我头头哥的博客, 请尊重版权, ...

  6. LINQ to XML 编程基础

    1.LINQ to XML类 以下的代码演示了如何使用LINQ to XML来快速创建一个xml: 隐藏行号 复制代码 ?创建 XML public static void CreateDocumen ...

  7. Linq学习笔记---Linq to Xml操作

    LINQ to XML的成员, 属性列表: 属性 说明 Document 获取此 XObject 的 XDocument  EmptySequence  获取空的元素集合  FirstAttribut ...

  8. C#学习之Linq to Xml

    前言 我相信很多从事.NET开发的,在.NET 3.5之前操作XML会比较麻烦,但是在此之后出现了Linq to Xml,而今天的主人公就是Linq to Xml,废话不多说,直接进入主题. 题外:最 ...

  9. C#中的Linq to Xml详解

    这篇文章主要介绍了C#中的Linq to Xml详解,本文给出转换步骤以及大量实例,讲解了生成xml.查询并修改xml.监听xml事件.处理xml流等内容,需要的朋友可以参考下 一.生成Xml 为了能 ...

随机推荐

  1. Python环境下如何安装爬虫需求的一些库

    是在CMD环境下的: request库pip install request 回车 pandas库 同理,pip install pandas :这里需要声明下,这个是不一定成功的,刚入门稍微看了一点 ...

  2. cookie 组成结构

    1.用抓包工具 fidller 只能看到 cookie 的 name 和 value 两个参数,实际上 cookie 还有其 它参数 2.以下是一个完整的 cookie 组成结构 cookie ={u ...

  3. [SQLSERVER] [GPO] Add the Log on as a service Right to an Account

    Add the Log on as a service Right to an Account Updated: August 8, 2008 Applies To: Windows Server 2 ...

  4. 在Eclipse中运行Jboss时出现java.lang.OutOfMemoryError:PermGen space及其解决方法

    在Eclipse中运行Jboss时出现java.lang.OutOfMemoryError:PermGen space及其解决方法 在Eclipse中运行Jboss时,时间太长可能有时候会出现java ...

  5. SQLTest系列之INSERT语句测试

    原文地址:https://yq.aliyun.com/articles/64375?spm=5176.100239.blogcont69187.22.fhUpoZ 摘要: 一款可以测试MSSQL Se ...

  6. Linux uptime命令详解

    常见的命令展示 uptime 08:21:34 up 36 min, 2 users, load average: 0.00, 0.00, 0.00 #当前服务器时间: 08:21:34 #当前服务器 ...

  7. BZOJ4184:shallot(线段树分治,线性基)

    Description 小苗去市场上买了一捆小葱苗,她突然一时兴起,于是她在每颗小葱苗上写上一个数字,然后把小葱叫过来玩游戏. 每个时刻她会给小葱一颗小葱苗或者是从小葱手里拿走一颗小葱苗,并且 让小葱 ...

  8. mapreduce设置setMapOutputKeyClass与setMapOutputValueClass原因

    一般的mapreduce的wordcount程序如下: public class WcMapper extends Mapper<LongWritable, Text, Text, LongWr ...

  9. curl_init 接口

    <?php// +----------------------------------------------------------------------// | ThinkPHP [ WE ...

  10. ZOJ 4100 浙江省第16届大学生程序设计竞赛 A题 Vertices in the Pocket 线段树+并查集

    正赛的时候完全没看这个题,事后winterzz告诉我他想出来的解法. 首先题意是给出n个点,m次操作. 操作有一种是连接两个点,另一种是求此时再为这个图连k条边,最少和最多能有几个联通块. 最少的求法 ...