संपादित करें

इसके माध्यम से साझा किया गया


XAttribute.SetValue(Object) Method

Definition

Sets the value of this attribute.

public:
 void SetValue(System::Object ^ value);
public void SetValue (object value);
member this.SetValue : obj -> unit
Public Sub SetValue (value As Object)

Parameters

value
Object

The value to assign to this attribute.

Exceptions

The value parameter is null.

The value is an XObject.

Examples

The following example creates an element with several attributes. It then changes the contents of one of the attributes.

XElement root = new XElement("Root",  
    new XAttribute("Att1", "content1"),  
    new XAttribute("Att2", "content2"),  
    new XAttribute("Att3", "content3")  
);  
XAttribute att = root.Attribute("Att2");  
att.SetValue("new content");  
Console.WriteLine(root);  
Dim root As XElement = <Root Att1="content1" Att2="content2" Att3="content3"/>  
Dim att As XAttribute = root.Attribute("Att2")  
att.SetValue("new content")  
Console.WriteLine(root)  

This example produces the following output:

<Root Att1="content1" Att2="new content" Att3="content3" />  

Remarks

The value is converted to its string representation and assigned to the Value property.

It is invalid to pass an instance of a class that derives from XObject, such as XElement or XAttribute.

This method will raise the Changed and the Changing events.

Applies to

See also