次の方法で共有


XmlConvert.ToString メソッド

厳密に型指定されたデータを等価の String 形式に変換します。

オーバーロードの一覧

BooleanString に変換します。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Shared Function ToString(Boolean) As String

[C#] public static string ToString(bool);

[C++] public: static String* ToString(bool);

[JScript] public static function ToString(Boolean) : String;

ByteString に変換します。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Shared Function ToString(Byte) As String

[C#] public static string ToString(byte);

[C++] public: static String* ToString(unsigned char);

[JScript] public static function ToString(Byte) : String;

CharString に変換します。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Shared Function ToString(Char) As String

[C#] public static string ToString(char);

[C++] public: static String* ToString(__wchar_t);

[JScript] public static function ToString(Char) : String;

DateTimeString に変換します。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Shared Function ToString(DateTime) As String

[C#] public static string ToString(DateTime);

[C++] public: static String* ToString(DateTime);

[JScript] public static function ToString(DateTime) : String;

DecimalString に変換します。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Shared Function ToString(Decimal) As String

[C#] public static string ToString(decimal);

[C++] public: static String* ToString(Decimal);

[JScript] public static function ToString(Decimal) : String;

DoubleString に変換します。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Shared Function ToString(Double) As String

[C#] public static string ToString(double);

[C++] public: static String* ToString(double);

[JScript] public static function ToString(double) : String;

GuidString に変換します。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Shared Function ToString(Guid) As String

[C#] public static string ToString(Guid);

[C++] public: static String* ToString(Guid);

[JScript] public static function ToString(Guid) : String;

Int16String に変換します。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Shared Function ToString(Short) As String

[C#] public static string ToString(short);

[C++] public: static String* ToString(short);

[JScript] public static function ToString(Int16) : String;

Int32String に変換します。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Shared Function ToString(Integer) As String

[C#] public static string ToString(int);

[C++] public: static String* ToString(int);

[JScript] public static function ToString(int) : String;

Int64String に変換します。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Shared Function ToString(Long) As String

[C#] public static string ToString(long);

[C++] public: static String* ToString(__int64);

[JScript] public static function ToString(long) : String;

SByteString に変換します。このメソッドは、CLS と互換性がありません。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Shared Function ToString(SByte) As String

[C#] public static string ToString(sbyte);

[C++] public: static String* ToString(char);

[JScript] public static function ToString(SByte) : String;

SingleString に変換します。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Shared Function ToString(Single) As String

[C#] public static string ToString(float);

[C++] public: static String* ToString(float);

[JScript] public static function ToString(float) : String;

TimeSpanString に変換します。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Shared Function ToString(TimeSpan) As String

[C#] public static string ToString(TimeSpan);

[C++] public: static String* ToString(TimeSpan);

[JScript] public static function ToString(TimeSpan) : String;

UInt16String に変換します。このメソッドは、CLS と互換性がありません。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Shared Function ToString(UInt16) As String

[C#] public static string ToString(ushort);

[C++] public: static String* ToString(unsigned short);

[JScript] public static function ToString(UInt16) : String;

UInt32String に変換します。このメソッドは、CLS と互換性がありません。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Shared Function ToString(UInt32) As String

[C#] public static string ToString(uint);

[C++] public: static String* ToString(unsigned int);

[JScript] public static function ToString(UInt32) : String;

UInt64String に変換します。このメソッドは、CLS と互換性がありません。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Shared Function ToString(UInt64) As String

[C#] public static string ToString(ulong);

[C++] public: static String* ToString(unsigned __int64);

[JScript] public static function ToString(UInt64) : String;

DateTimeString に変換します。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Shared Function ToString(DateTime, String) As String

[C#] public static string ToString(DateTime, string);

[C++] public: static String* ToString(DateTime, String*);

[JScript] public static function ToString(DateTime, String) : String;

Object から継承されます。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Overridable Function ToString() As String

[C#] public virtual string ToString();

[C++] public: virtual String* ToString();

[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++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

参照

XmlConvert クラス | XmlConvert メンバ | System.Xml 名前空間