Retrieving elements

The next example uses a SelectMany query to retrieve the hand tools in all toolboxes:

 
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;

class Program
{
    static void Main()
    {
        var bench = new XElement("Root",
            new XElement("subRoot",
            new XElement("X", "Y"), new XElement("X1", "Y1")),
            new XElement("E",
            new XElement("C", "D"),
            new XElement("A", "B")),
            new XComment("comment")
        );
        IEnumerable<string> query = from toolbox in bench.Elements() 
                                         from tool in toolbox.Elements() 
                                         where tool.Name == "E" 
                                         select tool.Value;
        foreach(string s in query){
            Console.WriteLine(s);        
        }
    }
}
  
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.