XElement.SetValue(Object) 方法
定義
設定這個元素的值。Sets the value of this element.
public:
void SetValue(System::Object ^ value);
public void SetValue (object value);
member this.SetValue : obj -> unit
Public Sub SetValue (value As Object)
參數
- value
- Object
要指派給這個元素的值。The value to assign to this element. 此值會轉換為其字串表示並指派給 Value 屬性。The value is converted to its string representation and assigned to the Value property.
例外狀況
value
為 null
。The value
is null
.
範例
下列範例會建立包含子項目的元素。The following example creates an element that contains a child element. 接著,它會使用這個方法來設定元素的值。It then sets the value of the element using this method.
XElement root = new XElement("Root",
new XElement("Child", "child content")
);
root.SetValue("new content");
Console.WriteLine(root);
Dim root As XElement = _
<Root>
<Child>child content</Child>
</Root>
root.SetValue("new content")
Console.WriteLine(root)
這個範例會產生下列輸出:This example produces the following output:
<Root>new content</Root>
備註
這個方法會引發 Changed 和 Changing 事件。This method will raise the Changed and the Changing events.
傳遞衍生自之類別的實例(例如)是不正確 XObject XElement 。It is invalid to pass an instance of a class that derives from XObject, such as XElement.