Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Konvertiert die String in ein Double-Äquivalent.
Namespace: System.Xml
Assembly: System.Xml (in system.xml.dll)
Syntax
'Declaration
Public Shared Function ToDouble ( _
s As String _
) As Double
'Usage
Dim s As String
Dim returnValue As Double
returnValue = XmlConvert.ToDouble(s)
public static double ToDouble (
string s
)
public:
static double ToDouble (
String^ s
)
public static double ToDouble (
String s
)
public static function ToDouble (
s : String
) : double
Parameter
- s
Die zu konvertierende Zeichenfolge.
Rückgabewert
Ein Double-Äquivalent der Zeichenfolge.
Ausnahmen
| Ausnahmetyp | Bedingung |
|---|---|
s ist NULL (Nothing in Visual Basic). |
|
s weist nicht das richtige Format auf. |
|
s stellt eine Zahl dar, die kleiner als Double.MinValue oder größer als Double.MaxValue ist. |
Hinweise
Wenn s INF oder -INF ist, gibt diese Methode Double.PositiveInfinity bzw. Double.NegativeInfinity zurück.
Beispiel
Im folgenden Beispiel werden ToDouble und ToDateTime zum Lesen von stark typisierten Daten verwendet.
Imports System
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
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();
}
}
#using <System.dll>
#using <System.xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
XmlTextReader^ reader = gcnew XmlTextReader( "orderData.xml" );
//Parse the file and pull out the order date and price.
while ( reader->Read() )
{
if ( reader->NodeType == XmlNodeType::Element )
{
if ( reader->Name->Equals( "order" ) )
{
DateTime orderDate = XmlConvert::ToDateTime( reader->GetAttribute( "date" ) );
Console::WriteLine( "order date: {0}", orderDate.ToString() );
}
else
if ( reader->Name->Equals( "price" ) )
{
Double price = XmlConvert::ToDouble( reader->ReadInnerXml() );
Console::WriteLine( "price: {0}", price );
}
}
}
//Close the reader.
reader->Close();
}
import System.*;
import System.IO.*;
import System.Xml.*;
public class Sample
{
public static void main(String[] args)
{
XmlTextReader reader = new XmlTextReader("orderData.xml");
//Parse the file and pull out the order date and price.
while (reader.Read()) {
if (reader.get_NodeType().Equals(XmlNodeType.Element)) {
if (reader.get_Name().Equals("order")) {
DateTime orderDate = XmlConvert.ToDateTime(
reader.GetAttribute("date"));
Console.WriteLine("order date: {0}", orderDate.ToString());
}
if (reader.get_Name().Equals("price")) {
double price = XmlConvert.ToDouble(reader.ReadInnerXml());
Console.WriteLine("price: {0}", System.Convert.ToString(
price));
}
}
}
//Close the reader.
reader.Close();
} //main
} //Sample
Im Beispiel wird die Datei orderData.xml als Eingabe verwendet.
<order date="2001-05-03">
<orderID>367A54</orderID>
<custID>32632</custID>
<price>19.95</price>
</order>
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
.NET Compact Framework
Unterstützt in: 2.0, 1.0
Siehe auch
Referenz
XmlConvert-Klasse
XmlConvert-Member
System.Xml-Namespace
PositiveInfinity
NegativeInfinity