语法
Visual Basic(声明)
Public Shared Function ToString ( _
value As Integer, _
toBase As Integer _
) As StringVisual Basic(用法)
Dim value As Integer
Dim toBase As Integer
Dim returnValue As String
returnValue = Convert.ToString(value, toBase)C#
public static string ToString (
int value,
int toBase
)C++
public:
static String^ ToString (
int value,
int toBase
)J#
public static String ToString (
int value,
int toBase
)JScript
public static function ToString (
value : int,
toBase : int
) : String
Visual Basic 复制代码
' Example of the Convert.ToString( Integer, Integer ) method.
Imports System
Imports Microsoft.VisualBasic
Module ConvertRadixIntDemo
Sub RunToStringDemo( )
Dim values as Integer( ) = { _
Integer.MinValue, _
-100, _
0, _
99999, _
Integer.MaxValue }
Dim radices as Integer( ) = { 2, 8, 10, 16 }
' Iterate through the values array.
Dim value as Integer
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 )
Console.WriteLine( "{0,13} {1,3} {2}", _
value, radix, valueString )
Next radix
Next value
End Sub
Sub Main( )
Console.WriteLine( _
"This example of Convert.ToString( Integer, Integer " & _
") generates " & vbCrLf & "the following output. It " & _
"converts several Integer 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( Integer, Integer ) generates
' the following output. It converts several Integer values to
' strings using the radixes supported by the method.
'
' Value Radix String
' ----- ----- ------
' -2147483648 2 10000000000000000000000000000000
' -2147483648 8 20000000000
' -2147483648 10 -2147483648
' -2147483648 16 80000000
' -100 2 11111111111111111111111110011100
' -100 8 37777777634
' -100 10 -100
' -100 16 ffffff9c
' 0 2 0
' 0 8 0
' 0 10 0
' 0 16 0
' 99999 2 11000011010011111
' 99999 8 303237
' 99999 10 99999
' 99999 16 1869f
' 2147483647 2 1111111111111111111111111111111
' 2147483647 8 17777777777
' 2147483647 10 2147483647
' 2147483647 16 7fffffffC# 复制代码
// Example of the Convert.ToString( int, int ) method.
using System;
// Iterate through the values array.
foreach( int value in values )
{
// Iterate through the radices.
foreach( int radix in radices )
{
// Convert a value with a radix.
string valueString =
Convert.ToString( value, radix );
static void Main( )
{
Console.WriteLine(
"This example of Convert.ToString( int, int ) " +
"generates \nthe following output. It converts several " +
"int values to \nstrings using the radixes supported " +
"by the method." );
Console.WriteLine(
"\n Value Radix String" +
"\n ----- ----- ------" );
RunToStringDemo( );
}
}
/*
This example of Convert.ToString( int, int ) generates
the following output. It converts several int values to
strings using the radixes supported by the method.