Byte.ToString メソッド
このインスタンスの数値を、それと等価の文字列に変換します。
オーバーロードの一覧
このインスタンスの数値を、それと等価の文字列に変換します。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Overrides Public Function ToString() As String
指定したカルチャ固有の書式情報を使用して、このインスタンスの数値を、それと等価の文字列に変換します。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Overridable Function ToString(IFormatProvider) As String
[JScript] public function ToString(IFormatProvider) : String;
指定した書式を使用して、このインスタンスの数値を、それと等価の文字列に変換します。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Function ToString(String) As String
指定した書式とカルチャ固有の書式情報を使用して、このインスタンスの数値を、それと等価の文字列に変換します。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Overridable Function ToString(String, IFormatProvider) As String
[C#] public virtual string ToString(string, IFormatProvider);
[C++] public: virtual String* ToString(String*, IFormatProvider*);
[JScript] public function ToString(String, IFormatProvider) : String;
使用例
[Visual Basic, C#, C++] ToString メソッドの複数のオーバーロードを使用して Byte 値を書式設定するコード例を次に示します。
[Visual Basic, C#, C++] メモ ここでは、ToString のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。
' Example for the Byte.ToString( ) methods.
Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic
Module ByteToStringDemo
Sub RunToStringDemo( )
Dim smallValue As Byte = 13
Dim largeValue As Byte = 234
' Format the Byte values without and with format strings.
Console.WriteLine( vbCrLf & "IFormatProvider is not used:" )
Console.WriteLine( " {0,-20}{1,10}{2,10}", _
"No format string:", smallValue.ToString( ), _
largeValue.ToString( ) )
Console.WriteLine( " {0,-20}{1,10}{2,10}", _
"'X2' format string:", smallValue.ToString( "X2" ), _
largeValue.ToString( "X2" ) )
' Get the NumberFormatInfo object from the
' invariant culture.
Dim culture As New CultureInfo( "" )
Dim numInfo As NumberFormatInfo = culture.NumberFormat
' Set the digit grouping to 1, set the digit separator
' to underscore, and set decimal digits to 0.
numInfo.NumberGroupSizes = New Integer( ) { 1 }
numInfo.NumberGroupSeparator = "_"
numInfo.NumberDecimalDigits = 0
' Use the NumberFormatInfo object for an IFormatProvider.
Console.WriteLine( vbCrLf & _
"A NumberFormatInfo object with digit group " & _
"size = 1 and " & vbCrLf & "digit separator " & _
"= '_' is used for the IFormatProvider:" )
Console.WriteLine( " {0,-20}{1,10}{2,10}", _
"No format string:", smallValue.ToString( numInfo ), _
largeValue.ToString( numInfo ) )
Console.WriteLine( " {0,-20}{1,10}{2,10}", _
"'N' format string:", _
smallValue.ToString( "N", numInfo ), _
largeValue.ToString( "N", numInfo ) )
End Sub
Sub Main( )
Console.WriteLine( "This example of" & vbCrLf & _
" Byte.ToString( )," & vbCrLf & _
" Byte.ToString( String )," & vbCrLf & _
" Byte.ToString( IFormatProvider ), and" & vbCrLf & _
" Byte.ToString( String, IFormatProvider )" & _
vbCrLf & "generates the following output when " & _
"formatting Byte values " & vbCrLf & _
"with combinations of format " & _
"strings and IFormatProvider." )
RunToStringDemo( )
End Sub
End Module
' This example of
' Byte.ToString( ),
' Byte.ToString( String ),
' Byte.ToString( IFormatProvider ), and
' Byte.ToString( String, IFormatProvider )
' generates the following output when formatting Byte values
' with combinations of format strings and IFormatProvider.
'
' IFormatProvider is not used:
' No format string: 13 234
' 'X2' format string: 0D EA
'
' A NumberFormatInfo object with digit group size = 1 and
' digit separator = '_' is used for the IFormatProvider:
' No format string: 13 234
' 'N' format string: 1_3 2_3_4
[C#]
// Example for the Byte.ToString( ) methods.
using System;
using System.Globalization;
class ByteToStringDemo
{
static void RunToStringDemo( )
{
byte smallValue = 13;
byte largeValue = 234;
// Format the Byte values without and with format strings.
Console.WriteLine( "\nIFormatProvider is not used:" );
Console.WriteLine( " {0,-20}{1,10}{2,10}",
"No format string:", smallValue.ToString( ),
largeValue.ToString( ) );
Console.WriteLine( " {0,-20}{1,10}{2,10}",
"'X2' format string:", smallValue.ToString( "X2" ),
largeValue.ToString( "X2" ) );
// Get the NumberFormatInfo object from the
// invariant culture.
CultureInfo culture = new CultureInfo( "" );
NumberFormatInfo numInfo = culture.NumberFormat;
// Set the digit grouping to 1, set the digit separator
// to underscore, and set decimal digits to 0.
numInfo.NumberGroupSizes = new int[ ] { 1 };
numInfo.NumberGroupSeparator = "_";
numInfo.NumberDecimalDigits = 0;
// Use the NumberFormatInfo object for an IFormatProvider.
Console.WriteLine(
"\nA NumberFormatInfo object with digit group " +
"size = 1 and \ndigit separator " +
"= '_' is used for the IFormatProvider:" );
Console.WriteLine( " {0,-20}{1,10}{2,10}",
"No format string:", smallValue.ToString( numInfo ),
largeValue.ToString( numInfo ) );
Console.WriteLine( " {0,-20}{1,10}{2,10}",
"'N' format string:",
smallValue.ToString( "N", numInfo ),
largeValue.ToString( "N", numInfo ) );
}
static void Main( )
{
Console.WriteLine( "This example of\n" +
" Byte.ToString( ),\n" +
" Byte.ToString( String ),\n" +
" Byte.ToString( IFormatProvider ), and\n" +
" Byte.ToString( String, IFormatProvider )\n" +
"generates the following output when formatting " +
"Byte values \nwith combinations of format " +
"strings and IFormatProvider." );
RunToStringDemo( );
}
}
/*
This example of
Byte.ToString( ),
Byte.ToString( String ),
Byte.ToString( IFormatProvider ), and
Byte.ToString( String, IFormatProvider )
generates the following output when formatting Byte values
with combinations of format strings and IFormatProvider.
IFormatProvider is not used:
No format string: 13 234
'X2' format string: 0D EA
A NumberFormatInfo object with digit group size = 1 and
digit separator = '_' is used for the IFormatProvider:
No format string: 13 234
'N' format string: 1_3 2_3_4
*/
[C++]
// Example for the Byte::ToString( ) methods.
#using <mscorlib.dll>
using namespace System;
using namespace System::Globalization;
void RunToStringDemo( )
{
Byte smallValue = 13;
Byte largeValue = 234;
// Format the Byte values without and with format strings.
Console::WriteLine( S"\nIFormatProvider is not used:" );
Console::WriteLine( S" {0,-20}{1,10}{2,10}",
S"No format string:", smallValue.ToString( ),
largeValue.ToString( ) );
Console::WriteLine( S" {0,-20}{1,10}{2,10}",
S"'X2' format string:", smallValue.ToString( S"X2" ),
largeValue.ToString( S"X2" ) );
// Get the NumberFormatInfo object from the invariant culture.
CultureInfo* culture = new CultureInfo( S"" );
NumberFormatInfo* numInfo = culture->NumberFormat;
// Set the digit grouping to 1, set the digit separator
// to underscore, and set decimal digits to 0.
Int32 sizes __gc [] = { 1 };
numInfo->NumberGroupSizes = sizes;
numInfo->NumberGroupSeparator = S"_";
numInfo->NumberDecimalDigits = 0;
// Use the NumberFormatInfo object for an IFormatProvider.
Console::WriteLine(
S"\nA NumberFormatInfo object with digit group "
S"size = 1 and \ndigit separator "
S"= '_' is used for the IFormatProvider:" );
Console::WriteLine( S" {0,-20}{1,10}{2,10}",
S"No format string:", smallValue.ToString( numInfo ),
largeValue.ToString( numInfo ) );
Console::WriteLine( S" {0,-20}{1,10}{2,10}",
S"'N' format string:", smallValue.ToString( S"N", numInfo ),
largeValue.ToString( S"N", numInfo ) );
}
void main( )
{
Console::WriteLine(
S"This example of\n Byte::ToString( ),\n"
S" Byte::ToString( String* ),\n"
S" Byte::ToString( IFormatProvider* ), and\n"
S" Byte::ToString( String*, IFormatProvider* )\n"
S"generates the following output when formatting "
S"Byte values \nwith combinations of format "
S"strings and IFormatProvider." );
RunToStringDemo( );
}
/*
This example of
Byte::ToString( ),
Byte::ToString( String* ),
Byte::ToString( IFormatProvider* ), and
Byte::ToString( String*, IFormatProvider* )
generates the following output when formatting Byte values
with combinations of format strings and IFormatProvider.
IFormatProvider is not used:
No format string: 13 234
'X2' format string: 0D EA
A NumberFormatInfo object with digit group size = 1 and
digit separator = '_' is used for the IFormatProvider:
No format string: 13 234
'N' format string: 1_3 2_3_4
*/
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。