XmlConvert.ToString メソッド

定義

厳密に型指定されたデータを同等の String 表現に変換します。

オーバーロード

名前 説明
ToString(Single)

SingleStringに変換します。

ToString(TimeSpan)

TimeSpanStringに変換します。

ToString(UInt16)

UInt16Stringに変換します。

ToString(UInt32)

UInt32Stringに変換します。

ToString(DateTimeOffset, String)

指定した DateTimeOffset を、指定した形式の String に変換します。

ToString(DateTime, String)

DateTimeStringに変換します。

ToString(DateTime, XmlDateTimeSerializationMode)

指定したDateTimeを使用して、StringXmlDateTimeSerializationModeに変換します。

ToString(SByte)

SByteStringに変換します。

ToString(UInt64)

UInt64Stringに変換します。

ToString(Int64)

Int64Stringに変換します。

ToString(Boolean)

BooleanStringに変換します。

ToString(Int16)

Int16Stringに変換します。

ToString(Guid)

GuidStringに変換します。

ToString(Double)

DoubleStringに変換します。

ToString(Decimal)

DecimalStringに変換します。

ToString(DateTimeOffset)

指定した DateTimeOffsetStringに変換します。

ToString(DateTime)
古い.
古い.

DateTimeStringに変換します。

ToString(Char)

CharStringに変換します。

ToString(Byte)

ByteStringに変換します。

ToString(Int32)

Int32Stringに変換します。

ToString(Single)

ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs

SingleStringに変換します。

public:
 static System::String ^ ToString(float value);
public static string ToString(float value);
static member ToString : single -> string
Public Shared Function ToString (value As Single) As String

パラメーター

value
Single

変換する値。

返品

Singleの文字列形式。

注釈

valueが Single.PositiveInfinity または Single.NegativeInfinity の場合、このメソッドはそれぞれ文字列 INF または -INF を返します。

こちらもご覧ください

適用対象

ToString(TimeSpan)

ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs

TimeSpanStringに変換します。

public:
 static System::String ^ ToString(TimeSpan value);
public static string ToString(TimeSpan value);
static member ToString : TimeSpan -> string
Public Shared Function ToString (value As TimeSpan) As String

パラメーター

value
TimeSpan

変換する値。

返品

TimeSpanの文字列形式。

適用対象

ToString(UInt16)

ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs

重要

この API は CLS 準拠ではありません。

UInt16Stringに変換します。

public:
 static System::String ^ ToString(System::UInt16 value);
[System.CLSCompliant(false)]
public static string ToString(ushort value);
[<System.CLSCompliant(false)>]
static member ToString : uint16 -> string
Public Shared Function ToString (value As UShort) As String

パラメーター

value
UInt16

変換する値。

返品

UInt16の文字列形式。

属性

適用対象

ToString(UInt32)

ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs

重要

この API は CLS 準拠ではありません。

UInt32Stringに変換します。

public:
 static System::String ^ ToString(System::UInt32 value);
[System.CLSCompliant(false)]
public static string ToString(uint value);
[<System.CLSCompliant(false)>]
static member ToString : uint32 -> string
Public Shared Function ToString (value As UInteger) As String

パラメーター

value
UInt32

変換する値。

返品

UInt32の文字列形式。

属性

適用対象

ToString(DateTimeOffset, String)

ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs

指定した DateTimeOffset を、指定した形式の String に変換します。

public:
 static System::String ^ ToString(DateTimeOffset value, System::String ^ format);
public static string ToString(DateTimeOffset value, string format);
static member ToString : DateTimeOffset * string -> string
Public Shared Function ToString (value As DateTimeOffset, format As String) As String

パラメーター

value
DateTimeOffset

変換する DateTimeOffset

format
String

valueの変換先の形式。 format パラメーターには、XML dateTime 型の W3C Recommendation の任意のサブセットを指定できます。 (詳細については、XML スキーマ仕様の dateTime セクションを参照してください。)

返品

指定したStringの指定した形式のDateTimeOffset表現。

次の例では、現在の時刻の DateTimeOffset 表現を、指定した形式の String に変換します。

using System;
using System.Xml;

class Example
{
    static void Main()
    {
        // Create the DateTimeOffset object and set the time to the current time.
        DateTimeOffset dto;
        dto = DateTimeOffset.Now;

        // Convert the DateTimeObject to a string in a specified format and display the result.
        // The specified format must be a subset of the W3C Recommendation for the XML dateTime type.
        String timeAsString = XmlConvert.ToString(dto, "yyyy-MM-ddTHH:mm:sszzzzzzz");
        Console.WriteLine(timeAsString);
    }
}
Imports System.Xml

Module Module1
    Sub Main()

        ' Create the DateTimeOffset object and set the time to the current time.
        Dim dto As DateTimeOffset
        dto = DateTimeOffset.Now

        ' Convert the DateTimeObject to a string in a specified format and display the result.
        ' The specified format must be a subset of the W3C Recommendation for the XML dateTime type.
        Dim timeAsString As [String] = XmlConvert.ToString(dto, "yyyy-MM-ddTHH:mm:sszzzzzzz")
        Console.WriteLine(timeAsString)

    End Sub
End Module

適用対象

ToString(DateTime, String)

ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs

DateTimeStringに変換します。

public:
 static System::String ^ ToString(DateTime value, System::String ^ format);
public static string ToString(DateTime value, string format);
static member ToString : DateTime * string -> string
Public Shared Function ToString (value As DateTime, format As String) As String

パラメーター

value
DateTime

変換する値。

format
String

変換された文字列の表示方法を定義する書式構造。 有効な形式には、"yyyy-MM-ddTHH:mm:sszzzzzz" とそのサブセットが含まれます。

返品

指定した形式の DateTime の文字列形式。

次の例では、データ型を文字列に変換し、コンソールに情報を書き込みます。

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();
  }
}
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

適用対象

ToString(DateTime, XmlDateTimeSerializationMode)

ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs

指定したDateTimeを使用して、StringXmlDateTimeSerializationModeに変換します。

public:
 static System::String ^ ToString(DateTime value, System::Xml::XmlDateTimeSerializationMode dateTimeOption);
public static string ToString(DateTime value, System.Xml.XmlDateTimeSerializationMode dateTimeOption);
static member ToString : DateTime * System.Xml.XmlDateTimeSerializationMode -> string
Public Shared Function ToString (value As DateTime, dateTimeOption As XmlDateTimeSerializationMode) As String

パラメーター

value
DateTime

変換する DateTime 値。

dateTimeOption
XmlDateTimeSerializationMode

XmlDateTimeSerializationMode値の処理方法を指定するDateTime値の 1 つ。

返品

Stringと同等のDateTime

例外

dateTimeOption値が無効です。

value値またはdateTimeOption値がnull

適用対象

ToString(SByte)

ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs

重要

この API は CLS 準拠ではありません。

SByteStringに変換します。

public:
 static System::String ^ ToString(System::SByte value);
[System.CLSCompliant(false)]
public static string ToString(sbyte value);
[<System.CLSCompliant(false)>]
static member ToString : sbyte -> string
Public Shared Function ToString (value As SByte) As String

パラメーター

value
SByte

変換する値。

返品

SByteの文字列形式。

属性

適用対象

ToString(UInt64)

ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs

重要

この API は CLS 準拠ではありません。

UInt64Stringに変換します。

public:
 static System::String ^ ToString(System::UInt64 value);
[System.CLSCompliant(false)]
public static string ToString(ulong value);
[<System.CLSCompliant(false)>]
static member ToString : uint64 -> string
Public Shared Function ToString (value As ULong) As String

パラメーター

value
UInt64

変換する値。

返品

UInt64の文字列形式。

属性

適用対象

ToString(Int64)

ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs

Int64Stringに変換します。

public:
 static System::String ^ ToString(long value);
public static string ToString(long value);
static member ToString : int64 -> string
Public Shared Function ToString (value As Long) As String

パラメーター

value
Int64

変換する値。

返品

Int64の文字列形式。

適用対象

ToString(Boolean)

ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs

BooleanStringに変換します。

public:
 static System::String ^ ToString(bool value);
public static string ToString(bool value);
static member ToString : bool -> string
Public Shared Function ToString (value As Boolean) As String

パラメーター

value
Boolean

変換する値。

返品

Booleanの文字列表現。つまり、"true" または "false" です。

適用対象

ToString(Int16)

ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs

Int16Stringに変換します。

public:
 static System::String ^ ToString(short value);
public static string ToString(short value);
static member ToString : int16 -> string
Public Shared Function ToString (value As Short) As String

パラメーター

value
Int16

変換する値。

返品

Int16の文字列形式。

次の例では、データ型を文字列に変換し、コンソールに情報を書き込みます。

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();
  }
}
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

適用対象

ToString(Guid)

ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs

GuidStringに変換します。

public:
 static System::String ^ ToString(Guid value);
public static string ToString(Guid value);
static member ToString : Guid -> string
Public Shared Function ToString (value As Guid) As String

パラメーター

value
Guid

変換する値。

返品

Guidの文字列形式。

適用対象

ToString(Double)

ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs

DoubleStringに変換します。

public:
 static System::String ^ ToString(double value);
public static string ToString(double value);
static member ToString : double -> string
Public Shared Function ToString (value As Double) As String

パラメーター

value
Double

変換する値。

返品

Doubleの文字列形式。

次の例では、データ型を文字列に変換し、コンソールに情報を書き込みます。

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();
  }
}
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

注釈

valueが Double.PositiveInfinity または Double.NegativeInfinity の場合、このメソッドは文字列 INF または -INF をそれぞれ返します。

こちらもご覧ください

適用対象

ToString(Decimal)

ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs

DecimalStringに変換します。

public:
 static System::String ^ ToString(System::Decimal value);
public static string ToString(decimal value);
static member ToString : decimal -> string
Public Shared Function ToString (value As Decimal) As String

パラメーター

value
Decimal

変換する値。

返品

Decimalの文字列形式。

適用対象

ToString(DateTimeOffset)

ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs

指定した DateTimeOffsetStringに変換します。

public:
 static System::String ^ ToString(DateTimeOffset value);
public static string ToString(DateTimeOffset value);
static member ToString : DateTimeOffset -> string
Public Shared Function ToString (value As DateTimeOffset) As String

パラメーター

value
DateTimeOffset

変換する DateTimeOffset

返品

指定されたStringDateTimeOffset表現。

次の例では、現在の時刻の DateTimeOffset 表現を Stringに変換します。

using System;
using System.Xml;

class Example
{
    static void Main()
    {
        // Create the DateTimeOffset object and set the time to the current time
        DateTimeOffset dto;
        dto = DateTimeOffset.Now;

        // Convert the DateTimeOffset object to a string and display the result
        string timeAsString = XmlConvert.ToString(dto);
        Console.WriteLine(timeAsString);
    }
}
Imports System.Xml

Module Module1
    Sub Main()

        ' Create the DateTimeOffset object and set the time to the current time
        Dim dto As DateTimeOffset
        dto = DateTimeOffset.Now

        ' Convert the DateTimeOffset object to a string and display the result
        Dim timeAsString As String = XmlConvert.ToString(dto)
        Console.WriteLine(timeAsString)

    End Sub
End Module

適用対象

ToString(DateTime)

ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs

注意事項

Use XmlConvert.ToString() that accepts an XmlDateTimeSerializationMode instead.

注意事項

Use XmlConvert.ToString() that takes in XmlDateTimeSerializationMode

DateTimeStringに変換します。

public:
 static System::String ^ ToString(DateTime value);
[System.Obsolete("Use XmlConvert.ToString() that accepts an XmlDateTimeSerializationMode instead.")]
public static string ToString(DateTime value);
[System.Obsolete("Use XmlConvert.ToString() that takes in XmlDateTimeSerializationMode")]
public static string ToString(DateTime value);
public static string ToString(DateTime value);
[<System.Obsolete("Use XmlConvert.ToString() that accepts an XmlDateTimeSerializationMode instead.")>]
static member ToString : DateTime -> string
[<System.Obsolete("Use XmlConvert.ToString() that takes in XmlDateTimeSerializationMode")>]
static member ToString : DateTime -> string
static member ToString : DateTime -> string
Public Shared Function ToString (value As DateTime) As String

パラメーター

value
DateTime

変換する値。

返品

'T' が定数リテラルである yyyy-MM-ddTHH:mm:ss 形式の DateTime の文字列形式。

属性

注釈

Note

XmlConvert.ToString(DateTime) メソッドは、.NET Framework の 2.0 バージョンでは廃止され、XmlConvert.ToString(DateTime, XmlDateTimeSerializationMode) メソッドに置き換えられました。 推奨モードは RoundtripKind。 完全一致が予想される場合は、書式指定文字列XmlConvert.ToString(DateTime, String)と共にyyyy-MM-ddTHH:mm:ss.fffffffzzzzzzを使用してください。

適用対象

ToString(Char)

ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs

CharStringに変換します。

public:
 static System::String ^ ToString(char value);
public static string ToString(char value);
static member ToString : char -> string
Public Shared Function ToString (value As Char) As String

パラメーター

value
Char

変換する値。

返品

Charの文字列形式。

適用対象

ToString(Byte)

ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs

ByteStringに変換します。

public:
 static System::String ^ ToString(System::Byte value);
public static string ToString(byte value);
static member ToString : byte -> string
Public Shared Function ToString (value As Byte) As String

パラメーター

value
Byte

変換する値。

返品

Byteの文字列形式。

適用対象

ToString(Int32)

ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs
ソース:
XmlConvert.cs

Int32Stringに変換します。

public:
 static System::String ^ ToString(int value);
public static string ToString(int value);
static member ToString : int -> string
Public Shared Function ToString (value As Integer) As String

パラメーター

value
Int32

変換する値。

返品

Int32の文字列形式。

適用対象