XmlConvert.ToDouble(String) Метод
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
public:
static double ToDouble(System::String ^ s);
public static double ToDouble(string s);
static member ToDouble : string -> double
Public Shared Function ToDouble (s As String) As Double
Параметры
- s
- String
Преобразуемая строка.
Возвращаемое значение
Эквивалент строки Double.
Исключения
s имеет значение null.
s имеет неправильный формат.
s представляет число меньше Double.MinValue или больше Double.MaxValue.
Примеры
В следующем примере для чтения строго типизированных данных используется ToDouble и ToDateTime .
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
XmlTextReader reader = new XmlTextReader("orderData.xml");
//Parse the file and pull out the order date and price.
while (reader.Read()){
if (reader.NodeType==XmlNodeType.Element){
switch(reader.Name){
case "order":
DateTime orderDate = XmlConvert.ToDateTime(reader.GetAttribute("date"));
Console.WriteLine("order date: {0}", orderDate.ToString());
break;
case "price":
Double price = XmlConvert.ToDouble(reader.ReadInnerXml());
Console.WriteLine("price: {0}", price.ToString());
break;
}
}
}
//Close the reader.
reader.Close();
}
}
Imports System.IO
Imports System.Xml
public class Sample
public shared sub Main()
Dim reader as XmlTextReader = new XmlTextReader("orderData.xml")
'Parse the file and pull out the order date and price.
while (reader.Read())
if (reader.NodeType=XmlNodeType.Element)
select case reader.Name
case "order":
Dim orderDate as DateTime = XmlConvert.ToDateTime(reader.GetAttribute("date"))
Console.WriteLine("order date: {0}", orderDate.ToString())
case "price":
Dim price as Double = XmlConvert.ToDouble(reader.ReadInnerXml())
Console.WriteLine("price: {0}", price.ToString())
end select
end if
end while
'Close the reader.
reader.Close()
end sub
end class
В этом примере в качестве входных данных используется файл orderData.xml.
<order date="2001-05-03">
<orderID>367A54</orderID>
<custID>32632</custID>
<price>19.95</price>
</order>
Комментарии
Если s имеет значение INF или -INF, этот метод возвращает Double.PositiveInfinity или Double.NegativeInfinity соответственно.