XComment.Value Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets or sets the string value of this comment.

Namespace:   System.Xml.Linq
Assembly:  System.Xml.Linq (in System.Xml.Linq.dll)

public string Value { get; set; }

Property Value

Type: System.String

A String that contains the string value of this comment.

Exception Condition

The value is null.

Unlike XElement and XAttribute, you cannot retrieve the contents of a comment by casting it to a string. Instead, you must use this property to retrieve the contents.

Setting this property will raise the Changed and the Changing events.

The following example creates a comment node. It then retrieves the contents of the comment node.

                XComment com = new XComment("This is a comment");

This example produces the following output:

This is a comment

Universal Windows Platform
Available since 8
.NET Framework
Available since 3.5
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top