System.Xml.XmlNodeReader.ReadElementContentAsLong

Syntax

public long ReadElementContentAsLong();

Parameters

This method takes no parameters.

Return Value

Returns the Int64 value of the current element’s content.

Remarks

Reads the content of the current element as a 64‑bit signed integer. The method advances the reader past the end of the element. If the element is empty, the method returns 0. If the content cannot be converted to a long, an XmlException is thrown.

Use this method when the XML element is expected to contain a numeric value that fits within the range of Int64.

Examples

Read a long value from an XML fragment:

string xml = @"<root><value>123456789</value></root>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
using (XmlNodeReader reader = new XmlNodeReader(doc))
{
    reader.MoveToContent();               // Move to the root element
    reader.ReadStartElement("root");      // Move to 
    long number = reader.ReadElementContentAsLong();
    Console.WriteLine(number); // 123456789
}

See Also