CSharp - Accessing an Element's First Attribute with the FirstAttribute Property

Description

Accessing an Element's First Attribute with the FirstAttribute Property

Demo

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

class Program/*w  ww .j  a va  2 s. c  om*/
{
    static void Main(string[] args){
            //  we will use this to store a reference to one of the elements in the XML tree.
            XElement firstParticipant;
            
            XDocument xDocument = new XDocument(
              new XElement("Books", firstParticipant =
                new XElement("Book",
                  new XAttribute("type", "Author"),
                  new XAttribute("experience", "first-time"),
                  new XAttribute("language", "English"),
                  new XElement("FirstName", "Joe"),
                  new XElement("LastName", "Ruby"))));
                  Console.WriteLine(firstParticipant.FirstAttribute);
    }
}

Result

Related Topic