64 ビット符号付き整数の値を、指定した基数で等価の String 形式に変換します。
Overloads Public Shared Function ToString( _
ByVal value As Long, _ ByVal toBase As Integer _) As String
[C#]
public static string ToString(longvalue,inttoBase);
[C++]
public: static String* ToString(__int64value,inttoBase);
[JScript]
public static function ToString(
value : long,toBase : int) : String;
パラメータ
- value
64 ビット符号付き整数。 - toBase
戻り値の基数。これは 2、8、10、または 16 である必要があります。
戻り値
基数 toBase での value の String 形式。
例外
例外の種類 | 条件 |
---|---|
ArgumentException | toBase が 2、8、10、または 16 ではありません。 |
使用例
[Visual Basic, C#, C++] ToString メソッドを使用し、このメソッドがサポートする基数に従って、複数の Int64 (64 ビット整数) を String に変換するコード例を次に示します。
' Example of the Convert.ToString( Long, Integer ) method.
Imports System
Imports Microsoft.VisualBasic
Module ConvertRadixLongDemo
Sub RunToStringDemo( )
Dim values as Long( ) = { _
Long.MinValue, _
-112233445566778899, _
4294967296, _
999999999999999999, _
Long.MaxValue }
Dim radices as Integer( ) = { 2, 8, 10, 16 }
' Iterate through the values array.
Dim value as Long
For Each value in values
' Iterate through the radices.
Dim radix as Integer
For Each radix in radices
' Convert a value with a radix.
Dim valueString As String = _
Convert.ToString( value, radix )
' Display the results; use two lines, if necessary.
If valueString.Length > 50 Then
Console.WriteLine( "{0,20} {1,3} " & _
vbCrLf & " {2}", _
value, radix, valueString )
Else
Console.WriteLine( "{0,20} {1,3} {2}", _
value, radix, valueString )
End If
Next radix
Next value
End Sub
Sub Main()
Console.WriteLine( _
"This example of Convert.ToString( Long, Integer ) " & _
"generates " & vbCrLf & "the following output. It " & _
"converts several Long values to " & vbCrLf & "strings " & _
"using the radixes supported by the method." )
Console.WriteLine( vbCrLf & _
" Value Radix String" & vbCrLf & _
" ----- ----- ------" )
RunToStringDemo( )
End Sub
End Module
' This example of Convert.ToString( Long, Integer ) generates
' the following output. It converts several Long values to
' strings using the radixes supported by the method.
'
' Value Radix String
' ----- ----- ------
' -9223372036854775808 2
' 1000000000000000000000000000000000000000000000000000000000000000
' -9223372036854775808 8 1000000000000000000000
' -9223372036854775808 10 -9223372036854775808
' -9223372036854775808 16 8000000000000000
' -112233445566778899 2
' 1111111001110001010001000100011010100001000100101111000111101101
' -112233445566778899 8 1771612104324104570755
' -112233445566778899 10 -112233445566778899
' -112233445566778899 16 fe714446a112f1ed
' 4294967296 2 100000000000000000000000000000000
' 4294967296 8 40000000000
' 4294967296 10 4294967296
' 4294967296 16 100000000
' 999999999999999999 2
' 110111100000101101101011001110100111011000111111111111111111
' 999999999999999999 8 67405553164730777777
' 999999999999999999 10 999999999999999999
' 999999999999999999 16 de0b6b3a763ffff
' 9223372036854775807 2
' 111111111111111111111111111111111111111111111111111111111111111
' 9223372036854775807 8 777777777777777777777
' 9223372036854775807 10 9223372036854775807
' 9223372036854775807 16 7fffffffffffffff
[C#]
// Example of the Convert.ToString( long, int ) method.
using System;
class ConvertRadixLongDemo
{
static void RunToStringDemo( )
{
long[ ] values = {
long.MinValue,
-112233445566778899,
4294967296,
999999999999999999,
long.MaxValue };
int[ ] radices = { 2, 8, 10, 16 };
// Iterate through the values array.
foreach( long value in values )
{
// Iterate through the radices.
foreach( int radix in radices )
{
// Convert a value with a radix.
string valueString =
Convert.ToString( value, radix );
// Display the results; use two lines, if necessary.
if( valueString.Length > 50 )
Console.WriteLine(
"{0,20} {1,3} \n {2}",
value, radix, valueString );
else
Console.WriteLine( "{0,20} {1,3} {2}",
value, radix, valueString );
}
}
}
static void Main( )
{
Console.WriteLine(
"This example of Convert.ToString( long, int ) " +
"generates \nthe following output. It converts several " +
"long values to \nstrings using the radixes supported " +
"by the method." );
Console.WriteLine(
"\n Value Radix String" +
"\n ----- ----- ------" );
RunToStringDemo( );
}
}
/*
This example of Convert.ToString( long, int ) generates
the following output. It converts several long values to
strings using the radixes supported by the method.
Value Radix String
----- ----- ------
-9223372036854775808 2
1000000000000000000000000000000000000000000000000000000000000000
-9223372036854775808 8 1000000000000000000000
-9223372036854775808 10 -9223372036854775808
-9223372036854775808 16 8000000000000000
-112233445566778899 2
1111111001110001010001000100011010100001000100101111000111101101
-112233445566778899 8 1771612104324104570755
-112233445566778899 10 -112233445566778899
-112233445566778899 16 fe714446a112f1ed
4294967296 2 100000000000000000000000000000000
4294967296 8 40000000000
4294967296 10 4294967296
4294967296 16 100000000
999999999999999999 2
110111100000101101101011001110100111011000111111111111111111
999999999999999999 8 67405553164730777777
999999999999999999 10 999999999999999999
999999999999999999 16 de0b6b3a763ffff
9223372036854775807 2
111111111111111111111111111111111111111111111111111111111111111
9223372036854775807 8 777777777777777777777
9223372036854775807 10 9223372036854775807
9223372036854775807 16 7fffffffffffffff
*/
[C++]
// Example of the Convert::ToString( Int64, Int32 ) method.
#using <mscorlib.dll>
using namespace System;
using namespace System::Collections;
void RunToStringDemo( )
{
__int64 values __gc [ ] = {
Int64::MinValue,
-112233445566778899,
4294967296,
999999999999999999,
Int64::MaxValue };
int radices[ 4 ] = { 2, 8, 10, 16 };
// Implement foreach( __int64 value in values ).
IEnumerator* myEnum = values->GetEnumerator( );
while( myEnum->MoveNext( ) )
{
__int64 value = Convert::ToInt64( myEnum->Current );
// Iterate through the radices.
for( int i = 0; i < 4; i++ )
{
// Convert a value with a radix.
int radix = radices[ i ];
String* valueString =
Convert::ToString( value, radix );
// Display the results; use two lines, if necessary.
if( valueString->Length > 50 )
Console::WriteLine(
S"{0,20} {1,3} \n {2}",
__box( value ), __box( radix ), valueString );
else
Console::WriteLine( S"{0,20} {1,3} {2}",
__box( value ), __box( radix ), valueString );
}
}
}
void main()
{
Console::WriteLine(
S"This example of Convert::ToString( __int64, int ) "
S"generates \nthe following output. It converts several "
S"__int64 values to \nstrings using the radixes supported "
S"by the method." );
Console::WriteLine(
S"\n Value Radix String"
S"\n ----- ----- ------" );
RunToStringDemo( );
}
/*
This example of Convert::ToString( __int64, int ) generates
the following output. It converts several __int64 values to
strings using the radixes supported by the method.
Value Radix String
----- ----- ------
-9223372036854775808 2
1000000000000000000000000000000000000000000000000000000000000000
-9223372036854775808 8 1000000000000000000000
-9223372036854775808 10 -9223372036854775808
-9223372036854775808 16 8000000000000000
-112233445566778899 2
1111111001110001010001000100011010100001000100101111000111101101
-112233445566778899 8 1771612104324104570755
-112233445566778899 10 -112233445566778899
-112233445566778899 16 fe714446a112f1ed
4294967296 2 100000000000000000000000000000000
4294967296 8 40000000000
4294967296 10 4294967296
4294967296 16 100000000
999999999999999999 2
110111100000101101101011001110100111011000111111111111111111
999999999999999999 8 67405553164730777777
999999999999999999 10 999999999999999999
999999999999999999 16 de0b6b3a763ffff
9223372036854775807 2
111111111111111111111111111111111111111111111111111111111111111
9223372036854775807 8 777777777777777777777
9223372036854775807 10 9223372036854775807
9223372036854775807 16 7fffffffffffffff
*/
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET
参照
Convert クラス | Convert メンバ | System 名前空間 | Convert.ToString オーバーロードの一覧