オーバーロードの一覧
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Shared Function ToDateTime(String) As DateTime
[JScript] public static function ToDateTime(String) : DateTime;
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Shared Function ToDateTime(String, String) As DateTime
[JScript] public static function ToDateTime(String, String) : DateTime;
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Shared Function ToDateTime(String, String()) As DateTime
[C++] public: static DateTime ToDateTime(String*, String*[]);
[JScript] public static function ToDateTime(String, String[]) : DateTime;
使用例
[Visual Basic, C#, C++] ToDouble および ToDateTime を使用して厳密に型指定されたデータを読み込む例を次に示します。
[Visual Basic, C#, C++] メモ ここでは、ToDateTime のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。
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
[C#]
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();
}
}
[C++]
#using <mscorlib.dll>
#using <System.dll>
#using <System.xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
XmlTextReader* reader = new XmlTextReader( S"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(S"order") )
{
DateTime orderDate = XmlConvert::ToDateTime(reader->GetAttribute(S"date"));
Console::WriteLine( S"order date: {0}", __box( orderDate )->ToString());
}
else if ( reader->Name->Equals(S"price") )
{
Double price = XmlConvert::ToDouble(reader->ReadInnerXml());
Console::WriteLine( S"price: {0}", __box( price ));
}
}
}
//Close the reader.
reader->Close();
}
この例では、入力として、 orderData.xml というファイルを使用しています。
<order date="2001-05-03">
<orderID>367A54</orderID>
<custID>32632</custID>
<price>19.95</price>
</order>
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。