XAttribute.ToString Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Convertit l’objet actuel XAttribute en représentation sous forme de chaîne.
public:
override System::String ^ ToString();
public override string ToString();
override this.ToString : unit -> string
Public Overrides Function ToString () As String
Retours
Contenant String la représentation textuelle XML d’un attribut et sa valeur.
Exemples
L’exemple suivant crée un élément avec plusieurs attributs. Il obtient ensuite un attribut et l’affiche et son contenu en appelant cette méthode.
XElement root = new XElement("Root",
new XAttribute("Att1", "content1"),
new XAttribute("Att2", "content2"),
new XAttribute("Att3", "content3")
);
XAttribute att = root.Attribute("Att2");
Console.WriteLine(att.ToString());
Dim root As XElement = <Root Att1="content1" Att2="content2" Att3="content3"/>
Dim att As XAttribute = root.Attribute("Att2")
Console.WriteLine(att.ToString())
Cet exemple produit la sortie suivante :
Att2="content2"
Remarques
Cette méthode retourne une chaîne sous la forme .AttributeName="content"
Warning
Lorsque cette méthode est appelée et XAttribute contient un caractère de contrôle, une exception est levée avec un message tel que : valeur hexadécimale 0x0B, est un caractère non valide.