zoukankan      html  css  js  c++  java
  • C# LINQ to XML示例

    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();
     
            }
     
    运行经结果:
     
  • 相关阅读:
    bzoj2006[NOI2010]超级钢琴
    bzoj1088[SCOI2005]扫雷
    bzoj1207[HNOI2004]打鼹鼠
    bzoj2132圈地计划
    bzoj2127happiness
    bzoj1037[ZJOI2008]生日聚会
    bzoj1031[JSOI2007]字符加密
    bzoj1566[noi2009]管道取珠
    bzoj2134单选错位
    vuejs之v-on小例子之实现购买数量的增加和减少
  • 原文地址:https://www.cnblogs.com/cncc/p/3415661.html
Copyright © 2011-2022 走看看