XText.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 root = new XElement("Root", "Some text");  
XText txtNode = root.Nodes().OfType<XText>().First();  
Console.WriteLine(txtNode.Value);  
txtNode.Value = "New text";  
Console.WriteLine(txtNode.Value);  

root.Value = "Newer text";  
txtNode = root.Nodes().OfType<XText>().First();  
Console.WriteLine(txtNode.Value);  
Dim root As XElement = <Root>Some text</Root>  
Dim txtNode As XText = root.Nodes().OfType(Of XText).First()  
Console.WriteLine(txtNode.Value)  
txtNode.Value = "New text"  
Console.WriteLine(txtNode.Value)  

root.Value = "Newer text"  
txtNode = root.Nodes().OfType(Of XText).First()  
Console.WriteLine(txtNode.Value)  

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

Some text  
New text  
Newer text  

備註

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

適用於

另請參閱