public long ReadElementContentAsLong();
This method takes no parameters.
Returns the Int64
value of the current element’s content.
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
.
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
}