XElement.SetValue(Object) XElement.SetValue(Object) XElement.SetValue(Object) XElement.SetValue(Object) Method

定義

設定這個元素的值。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 Object Object Object

要指派給這個元素的值。The value to assign to this element. 此值會轉換為其字串表示並指派給 Value 屬性。The value is converted to its string representation and assigned to the Value property.

例外狀況

範例

下列範例會建立包含子專案的元素。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 和 @no__t 1 事件。This method will raise the Changed and the Changing events.

傳遞衍生自 XObject 的類別實例是不正確,例如 XElementIt is invalid to pass an instance of a class that derives from XObject, such as XElement.

適用於

另請參閱