XAttribute.ToString 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將目前 XAttribute 的物件轉換成字串表示。
public:
override System::String ^ ToString();
public override string ToString();
override this.ToString : unit -> string
Public Overrides Function ToString () As String
傳回
String A 包含屬性的 XML 文字表示及其值。
範例
以下範例建立一個具有多個屬性的元素。 接著它會取得一個屬性,並透過呼叫這個方法來顯示該屬性及其內容。
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())
此範例會產生下列輸出:
Att2="content2"
備註
此方法回傳一個字串形式為 AttributeName="content"。
警告
當此方法被呼叫且 XAttribute 包含控制字元時,會拋出異常並傳達訊息,例如:十六進位值 0x0B 是無效字元。