XmlConvert.ToString メソッド
厳密に型指定されたデータを等価の String 形式に変換します。
オーバーロードの一覧
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Shared Function ToString(Boolean) As String
[JScript] public static function ToString(Boolean) : String;
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Shared Function ToString(Byte) As String
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Shared Function ToString(Char) As String
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Shared Function ToString(DateTime) As String
[JScript] public static function ToString(DateTime) : String;
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Shared Function ToString(Decimal) As String
[JScript] public static function ToString(Decimal) : String;
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Shared Function ToString(Double) As String
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Shared Function ToString(Guid) As String
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Shared Function ToString(Short) As String
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Shared Function ToString(Integer) As String
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Shared Function ToString(Long) As String
SByte を String に変換します。このメソッドは、CLS と互換性がありません。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Shared Function ToString(SByte) As String
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Shared Function ToString(Single) As String
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Shared Function ToString(TimeSpan) As String
[JScript] public static function ToString(TimeSpan) : String;
UInt16 を String に変換します。このメソッドは、CLS と互換性がありません。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Shared Function ToString(UInt16) As String
UInt32 を String に変換します。このメソッドは、CLS と互換性がありません。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Shared Function ToString(UInt32) As String
UInt64 を String に変換します。このメソッドは、CLS と互換性がありません。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Shared Function ToString(UInt64) As String
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Shared Function ToString(DateTime, String) As String
[JScript] public static function ToString(DateTime, String) : String;
Object から継承されます。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Overridable Function ToString() As String
[JScript] public function ToString() : String;
使用例
[Visual Basic, C#, C++] データ型を文字列に変換してから、情報をコンソールに書き込む例を次に示します。
[Visual Basic, C#, C++] メモ ここでは、ToString のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。
Imports System
Imports System.IO
Imports System.Xml
public class Sample
public shared sub Main()
'Define the order data. They will be converted to string
'before being written out.
Dim custID as Int16 = 32632
Dim orderID as String = "367A54"
Dim orderDate as DateTime
orderDate = DateTime.Now
Dim price as Double = 19.95
'Create a writer that outputs to the console.
Dim writer as XmlTextWriter = new XmlTextWriter (Console.Out)
'Use indenting for readability
writer.Formatting = Formatting.Indented
'Write an element (this one is the root)
writer.WriteStartElement("order")
'Write the order date.
writer.WriteAttributeString("date", XmlConvert.ToString(orderDate, "yyyy-MM-dd"))
'Write the order time.
writer.WriteAttributeString("time", XmlConvert.ToString(orderDate, "HH:mm:ss"))
'Write the order data.
writer.WriteElementString("orderID", orderID)
writer.WriteElementString("custID", XmlConvert.ToString(custID))
writer.WriteElementString("price", XmlConvert.ToString(price))
'Write the close tag for the root element
writer.WriteEndElement()
'Write the XML and close the writer
writer.Flush()
writer.Close()
end sub
end class
[C#]
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
//Define the order data. They will be converted to string
//before being written out.
Int16 custID = 32632;
String orderID = "367A54";
DateTime orderDate = new DateTime();
orderDate = DateTime.Now;
Double price = 19.95;
//Create a writer that outputs to the console.
XmlTextWriter writer = new XmlTextWriter (Console.Out);
writer.Formatting = Formatting.Indented;
//Write an element (this one is the root)
writer.WriteStartElement("order");
//Write the order date.
writer.WriteAttributeString("date", XmlConvert.ToString(orderDate, "yyyy-MM-dd"));
//Write the order time.
writer.WriteAttributeString("time", XmlConvert.ToString(orderDate, "HH:mm:ss"));
//Write the order data.
writer.WriteElementString("orderID", orderID);
writer.WriteElementString("custID", XmlConvert.ToString(custID));
writer.WriteElementString("price", XmlConvert.ToString(price));
//Write the close tag for the root element
writer.WriteEndElement();
//Write the XML and close the writer
writer.Close();
}
}
[C++]
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
//Define the order data. They will be converted to string
//before being written out.
Int16 custID = 32632;
String* orderID = S"367A54";
DateTime orderDate = DateTime::Now;
Double price = 19.95;
//Create a writer that outputs to the console.
XmlTextWriter* writer = new XmlTextWriter (Console::Out);
writer->Formatting = Formatting::Indented;
//Write an element (this one is the root)
writer->WriteStartElement(S"order");
//Write the order date.
writer->WriteAttributeString(S"date", XmlConvert::ToString(orderDate, S"yyyy-MM-dd"));
//Write the order time.
writer->WriteAttributeString(S"time", XmlConvert::ToString(orderDate, S"HH:mm:ss"));
//Write the order data.
writer->WriteElementString(S"orderID", orderID);
writer->WriteElementString(S"custID", XmlConvert::ToString(custID));
writer->WriteElementString(S"price", XmlConvert::ToString(price));
//Write the close tag for the root element
writer->WriteEndElement();
//Write the XML and close the writer
writer->Close();
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。