ReadContentAsDouble Method
Reads the current node as a double value.
Namespace
System.Xml
Assembly
System.Xml.dll
Syntax
public override double ReadContentAsDouble();
Return Value
Returns the double value represented by the current node's content.
Exceptions
| Exception | Condition |
|---|---|
InvalidOperationException | The reader is not positioned on a node that can be read as a double. |
FormatException | The content cannot be converted to a double. |
OverflowException | The numeric value is outside the range of a double. |
Remarks
ReadContentAsDouble is equivalent to calling ReadContentAs with typeof(double).
It parses the content according to the conventions of the invariant culture.
Example
// Sample XML
string xml = @"<price>123.45</price>";
// Create an XmlDocument and load the XML
var doc = new System.Xml.XmlDocument();
doc.LoadXml(xml);
// Create a XmlNodeReader positioned on the root element
using var reader = new System.Xml.XmlNodeReader(doc);
// Move to the element node
reader.Read(); // XmlNodeType.Element (price)
// Read the content as double
double price = reader.ReadContentAsDouble();
System.Console.WriteLine($"Price: {price}"); // Output: Price: 123.45