XmlConvert.ToString メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
厳密に型指定されたデータを等価の String 形式に変換します。
オーバーロード
ToString(Single)
- ソース:
- XmlConvert.cs
- ソース:
- XmlConvert.cs
- ソース:
- XmlConvert.cs
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 の文字列形式。
注釈
が Single.PositiveInfinity または Single.NegativeInfinity の場合 value
、このメソッドは文字列 INF または -INF をそれぞれ返します。
こちらもご覧ください
適用対象
ToString(TimeSpan)
- ソース:
- XmlConvert.cs
- ソース:
- XmlConvert.cs
- ソース:
- XmlConvert.cs
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
重要
この API は CLS 準拠ではありません。
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
重要
この API は CLS 準拠ではありません。
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
指定した 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
変換後の s
の形式。 フォーマット パラメーターには、W3C 勧告の XML dateTime 型の任意のサブセットを指定できます。 (詳細については、XML スキーマ仕様の dateTime セクションを参照してください。)
戻り値
指定した DateTimeOffset の指定した形式での String 表現。
例
次の例では、 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
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.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 = "367A54";
DateTime orderDate = DateTime::Now;
Double price = 19.95;
//Create a writer that outputs to the console.
XmlTextWriter^ writer = gcnew 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();
}
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
指定された XmlDateTimeSerializationMode を使用して、DateTime を String に変換します。
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
パラメーター
- dateTimeOption
- XmlDateTimeSerializationMode
DateTime 値を処理する方法を指定する XmlDateTimeSerializationMode 値の 1 つ。
戻り値
例外
dateTimeOption
値が有効ではありません。
value
または dateTimeOption
の値が null
です。
適用対象
ToString(SByte)
- ソース:
- XmlConvert.cs
- ソース:
- XmlConvert.cs
- ソース:
- XmlConvert.cs
重要
この API は CLS 準拠ではありません。
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
重要
この API は CLS 準拠ではありません。
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
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
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
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.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 = "367A54";
DateTime orderDate = DateTime::Now;
Double price = 19.95;
//Create a writer that outputs to the console.
XmlTextWriter^ writer = gcnew 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();
}
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
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
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.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 = "367A54";
DateTime orderDate = DateTime::Now;
Double price = 19.95;
//Create a writer that outputs to the console.
XmlTextWriter^ writer = gcnew 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();
}
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
注釈
が Double.PositiveInfinity または Double.NegativeInfinity の場合 value
、このメソッドは文字列 INF または -INF をそれぞれ返します。
こちらもご覧ください
適用対象
ToString(Decimal)
- ソース:
- XmlConvert.cs
- ソース:
- XmlConvert.cs
- ソース:
- XmlConvert.cs
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
指定した DateTimeOffset を String に変換します。
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。
戻り値
指定した DateTimeOffset の String 表現。
例
次の例では、 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
注意事項
Use XmlConvert.ToString() that takes in XmlDateTimeSerializationMode
注意事項
Use XmlConvert.ToString() that accepts an XmlDateTimeSerializationMode instead.
public:
static System::String ^ ToString(DateTime value);
[System.Obsolete("Use XmlConvert.ToString() that takes in XmlDateTimeSerializationMode")]
public static string ToString (DateTime value);
[System.Obsolete("Use XmlConvert.ToString() that accepts an XmlDateTimeSerializationMode instead.")]
public static string ToString (DateTime value);
public static string ToString (DateTime value);
[<System.Obsolete("Use XmlConvert.ToString() that takes in XmlDateTimeSerializationMode")>]
static member ToString : DateTime -> string
[<System.Obsolete("Use XmlConvert.ToString() that accepts an XmlDateTimeSerializationMode instead.")>]
static member ToString : DateTime -> string
static member ToString : DateTime -> string
Public Shared Function ToString (value As DateTime) As String
パラメーター
- value
- DateTime
変換する値。
戻り値
yyyy-MM-ddTHH:mm:ss の形式での DateTime
の文字列形式。'T' は定数リテラル。
- 属性
注釈
注意
メソッドはXmlConvert.ToString(DateTime)、.NET Frameworkの 2.0 バージョンでは古く、メソッドにXmlConvert.ToString(DateTime, XmlDateTimeSerializationMode)置き換えられました。
推奨されるモードは です RoundtripKind。 完全一致が必要な場合は、書式指定文字列 yyyy-MM-ddTHH:mm:ss.fffffffzzzzzz
と共に を使用XmlConvert.ToString(DateTime, String)してください。
適用対象
ToString(Char)
- ソース:
- XmlConvert.cs
- ソース:
- XmlConvert.cs
- ソース:
- XmlConvert.cs
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
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
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 の文字列形式。
適用対象
.NET