Redigera

Dela via


XAttribute.ToString Method

Definition

Converts the current XAttribute object to a string representation.

public:
 override System::String ^ ToString();
public override string ToString ();
override this.ToString : unit -> string
Public Overrides Function ToString () As String

Returns

A String containing the XML text representation of an attribute and its value.

Examples

The following example creates an element with several attributes. It then gets an attribute and displays it and its content by calling this method.

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())  

This example produces the following output:

Att2="content2"  

Remarks

This method returns a string in the form of AttributeName="content".

Warning

When this method is called and XAttribute contains control character, an exception is thrown with a message like: hexadecimal value 0x0B, is an invalid character.

Applies to

See also