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. 在Eclipse中运行Jboss时出现java.lang.OutOfMemoryError:PermGen space及其解决方法

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

  2. CSS| font property

    字體屬性 常用的CSS字体名称 宋体 SimSun 黑体 SimHei 微软雅黑 Microsoft YaHei 微软正黑体 Microsoft JhengHei 新宋体 NSimSun 新细明体 P ...

  3. MySQL 支持utf8mb4

    utf8mb4 utf8mb3 utf8 Refer to The utf8mb4 Character Set The utf8 Character Set (Alias for utf8mb3) M ...

  4. 转:asp.net mvc下的多语言方案 包含Html,Javascript和图片

    可以不使用微软的Resource文件,而是将所有的词汇放入在一个txt的词典之中,便于维护. 步骤如下: 1)在整个程序的入口处global.asax.cs加入函数 private void Read ...

  5. Difference between HashMap and Hashtable | HashMap Vs Hashtable

    Both the HashMap and Hashtable implement the interface java.util.Map but there are some slight diffe ...

  6. 开源作业调度框架 - Quartz.NET - ASP.NET部署

    经过这次使用实践,感觉Quartz.NET使用起来方便快捷 但是在发布部署时我们会遇到一个问题 那就是当Web应用程序经常没有按照预计的时间去执行. 那问题出在哪里了呢? 根据以往的经验很容易就可以找 ...

  7. windows系统显示隐藏文件以及显示文件扩展名

    1.XP系统 打开“我的电脑”,“工具”,“文件夹选项” 勾选如下图 2.win7系统 打开“计算机”,“组织”,“文件夹和搜索选项” 勾选如下图 3.win10系统 打开“此电脑”,“查看”,勾选如 ...

  8. 【python】关于python中模块导入的总结

    precondition:比如我有如下这样的文件目录结构 说明:add和debug两个包都隶属于src目录,它们是同级目录,其中在add路径下有一个add.py的模块,里面定义了一个jiafa()的函 ...

  9. git版本管理工具-git的概述

    什么是git Git是一个开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目的一种工具 Git 与常用的版本控制工具 CVS, Subversion 等不同,它采用了分布式版本库的方式,不 ...

  10. tomcat:8080/返回404;/etc/hosts(identifier-Namespace-scope)

    我以为 就oracle 的 oracle db ,weblogic喜欢和 hostname 死磕: 没想到开源的tomcat也是如出一辙,名不正则言不顺,为什么,“名”的力量这么大呢?命名空间. 有个 ...