SByte.ToString メソッド
このインスタンスの数値を、それと等価な文字列形式に変換します。
SByte 型は CLS との互換性がありません。CLS と互換性のある型は、Int16 です。CLS との互換性に関する詳細については 「共通言語仕様の概要」 を参照してください。
オーバーロードの一覧
このインスタンスの数値を、それと等価な文字列形式に変換します。
.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 メソッドの複数のオーバーロードを使用して SByte (符号付きバイト) 値を書式化するコード例を次に示します。
[Visual Basic, C#, C++] メモ ここでは、ToString のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。
' Example for the SByte.ToString( ) methods.
Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic
Module SByteToStringDemo
Sub RunToStringDemo( )
Dim smallValue As SByte = Convert.ToSByte( -99 )
Dim largeValue As SByte = Convert.ToSByte( 123 )
' Format the SByte 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 decimal digits to 0. Set the negative pattern to ( ).
numInfo.NumberNegativePattern = 0
numInfo.NumberDecimalDigits = 0
' Use the NumberFormatInfo object for an IFormatProvider.
Console.WriteLine( vbCrLf & _
"A NumberFormatInfo object with negative pattern " & _
"= ( ) and " & vbCrLf & "no decimal digits " & _
"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 & _
" SByte.ToString( )," & vbCrLf & _
" SByte.ToString( String )," & vbCrLf & _
" SByte.ToString( IFormatProvider ), and" & vbCrLf & _
" SByte.ToString( String, IFormatProvider )" & _
vbCrLf & "generates the following output when " & _
"formatting SByte values " & vbCrLf & _
"with combinations of format " & _
"strings and IFormatProvider." )
RunToStringDemo( )
End Sub
End Module
' This example of
' SByte.ToString( ),
' SByte.ToString( String ),
' SByte.ToString( IFormatProvider ), and
' SByte.ToString( String, IFormatProvider )
' generates the following output when formatting SByte values
' with combinations of format strings and IFormatProvider.
'
' IFormatProvider is not used:
' No format string: -99 123
' 'X2' format string: 9D 7B
'
' A NumberFormatInfo object with negative pattern = ( ) and
' no decimal digits is used for the IFormatProvider:
' No format string: -99 123
' 'N' format string: (99) 123
[C#]
// Example for the SByte.ToString( ) methods.
using System;
using System.Globalization;
public class SByteToStringDemo
{
static void RunToStringDemo( )
{
SByte smallValue = -99;
SByte largeValue = 123;
// Format the SByte 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 decimal digits to 0. Set the negative pattern to ( ).
numInfo.NumberDecimalDigits = 0;
numInfo.NumberNegativePattern = 0;
// Use the NumberFormatInfo object for an IFormatProvider.
Console.WriteLine( "\nA NumberFormatInfo " +
"object with negative pattern = ( ) and \nno " +
"decimal digits 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 SByte.ToString( ),\n" +
" SByte.ToString( string ),\n" +
" SByte.ToString( IFormatProvider ), and\n" +
" SByte.ToString( string, IFormatProvider )\n" +
"generates the following output when formatting " +
"SByte values \nwith combinations of format " +
"strings and IFormatProvider." );
RunToStringDemo( );
}
}
/*
This example of
SByte.ToString( ),
SByte.ToString( string ),
SByte.ToString( IFormatProvider ), and
SByte.ToString( string, IFormatProvider )
generates the following output when formatting SByte values
with combinations of format strings and IFormatProvider.
IFormatProvider is not used:
No format string: -99 123
'X2' format string: 9D 7B
A NumberFormatInfo object with negative pattern = ( ) and
no decimal digits is used for the IFormatProvider:
No format string: -99 123
'N' format string: (99) 123
*/
[C++]
// Example for the SByte::ToString( ) methods.
#using <mscorlib.dll>
using namespace System;
using namespace System::Globalization;
void RunToStringDemo( )
{
SByte smallValue = -99;
SByte largeValue = 123;
// 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 decimal digits to 0. Set the negative pattern to ( ).
numInfo->NumberDecimalDigits = 0;
numInfo->NumberNegativePattern = 0;
// Use the NumberFormatInfo object for an IFormatProvider.
Console::WriteLine( S"\nA NumberFormatInfo "
S"object with negative pattern = ( ) and \nno "
S"decimal digits 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 SByte::ToString( ),\n"
S" SByte::ToString( String* ),\n"
S" SByte::ToString( IFormatProvider* ), and\n"
S" SByte::ToString( String*, IFormatProvider* )\n"
S"generates the following output when formatting "
S"SByte values \nwith combinations of format "
S"strings and IFormatProvider." );
RunToStringDemo( );
}
/*
This example of
SByte::ToString( ),
SByte::ToString( String* ),
SByte::ToString( IFormatProvider* ), and
SByte::ToString( String*, IFormatProvider* )
generates the following output when formatting SByte values
with combinations of format strings and IFormatProvider.
IFormatProvider is not used:
No format string: -99 123
'X2' format string: 9D 7B
A NumberFormatInfo object with negative pattern = ( ) and
no decimal digits is used for the IFormatProvider:
No format string: -99 123
'N' format string: (99) 123
*/
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。