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. Oracle EBS INV 创建物料搬运单

    Create or Replace PROCEDURE ProcessMoveOrder AS -- Common Declarations l_api_version NUMBER := 1.0; ...

  2. (转载)令人迷糊的Oracle递归查询(start with)

    转载地址:https://blog.csdn.net/weiwenhp/article/details/8218091 备注:如有侵权,请联系立即删除. 写代码时碰到要弄清楚Oracle的role之间 ...

  3. 向Sql Server数据库插入中文时显示乱码的解决办法 (转)

    转自:http://blog.csdn.net/wizardlun/article/details/4577658 參考:http://shareideas.blog.51cto.com/362642 ...

  4. linux 通过 mac地址 查询 ip 和 清除arp 缓存

    问题重述: 今天,突然找不到vm 的ip 了,但是可以从网卡状态上看到其 mac 地址,并且确定主机是启动状态,网络状态良好(后来发现因为子网掩码的问题,导致虚拟机和网关之间不通信,从而导致其他网络的 ...

  5. GridBagLayout布局管理器应用详解

    http://www.cnblogs.com/kungfupanda/p/7220217.html GridBagLayout布局管理器应用详解 很多情况下,我们已经不需要通过编写代码来实现一个应用程 ...

  6. 用apiDoc简化接口开发

    身为程序员最讨厌看到的代码没有注释,自己的代码却讨厌写注释,觉得麻烦,接口也是这样. 比如公司要做一个H5活动的页面,开发文档已经发到后端开发.设计.与前端的邮箱了,其实这个时候就可以开始开发了.开发 ...

  7. DOS 总结

    shutdown -s -t 30 指定在30秒之后自动关闭计算机. + L 返回登录页面 netstat 最近访问IP Regedit 打开注册表

  8. 利用MSF的MS08_067模块攻击windows server 2003 SP2中文版系统

    一.测试环境 攻击机:kali(NMAP+MSF) 靶机:windows server 2003 SP2 中文版 利用漏洞:MS08_067 二.漏洞描述 MS08-067漏洞的全称为“Windows ...

  9. 给SVN设置代理

    XP系统在C:\Documents and Settings\Administrator\Application Data\Subversion目录下 win7及以上系统在C:\Users\admin ...

  10. make报错

    笔记本Ubuntu16.04环境下,进入项目的src目录下执行make操作,发现报如下错误 /bin/sh: 1: /usr/bin/libtool: not found makefile:89: r ...