XElement.Value 屬性

定義

取得或設定這個元素的串連文字內容。

public:
 property System::String ^ Value { System::String ^ get(); void set(System::String ^ value); };
public string Value { get; set; }
member this.Value : string with get, set
Public Property Value As String

屬性值

String,包含這個項目的所有文字內容。 如果有多個文字節點,將會串連它們。

範例

下列範例會使用這個屬性來擷取具有混合內容的專案文字。

XElement el = XElement.Parse("<Root>This is <b>mixed</b> content</Root>");
Console.WriteLine("{0}", el.Value);
Dim el As XElement = <Root>This is <b>mixed</b> content</Root>
Console.WriteLine("{0}", el.Value)

這個範例會產生下列輸出:

This is mixed content

備註

您可以使用這個屬性來取得或設定元素的值。

設定此屬性將會引發 ChangedChanging 事件。

如果您想要取得元素的值,但不確定它存在,使用明確轉換運算子會比較方便,並將專案指派給可為 Null 的類型,例如 stringNullable<T>Int32 。 如果專案不存在,可為 Null 的型別會設定為 null 。 相反地,如果您想要使用這個屬性,您必須先確定 Element 方法不會在存取此屬性之前傳回 null

適用於

另請參閱