Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Convert.ToString Method (Int32, Int32)

Converts the value of a 32-bit signed integer to its equivalent String representation in a specified base.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

public static string ToString (
	int value,
	int toBase
)
public static String ToString (
	int value, 
	int toBase
)
public static function ToString (
	value : int, 
	toBase : int
) : String

Parameters

value

A 32-bit signed integer.

toBase

The base of the return value, which must be 2, 8, 10, or 16.

Return Value

The String representation of value in base toBase.

Exception typeCondition

ArgumentException

toBase is not 2, 8, 10, or 16.

The following code example converts several 32-bit integers to String s with the ToString method in the radixes supported by the method.

// Example of the Convert.ToString( int, int ) method.
using System;

class ConvertRadixIntDemo
{
    static void RunToStringDemo( )
    {
        int[ ] values = {
            int.MinValue, 
            -100, 
            0, 
            99999, 
            int.MaxValue };
        int[ ]  radices = { 2, 8, 10, 16 };

        // 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 );

                Console.WriteLine( "{0,13}  {1,3}    {2}", 
                    value, radix, valueString );
            }
        }
    } 

    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.

     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    7fffffff
*/

// Example of the Convert.ToString( int, int ) method.
import System.* ;

class ConvertRadixIntDemo
{   
    static void RunToStringDemo() 
    {
        int values[] =  { -2147483648, -100, 0, 99999, 2147483647 };
        int radices[] =  { 2, 8, 10, 16 };
        // Iterate through the values array.
        for(int iCtr=0; iCtr < values.length; iCtr++) {
            int value = values[iCtr];
      
            // Iterate through the radices.
            for(int iCtr1=0; iCtr1<radices.length; iCtr1++) {
                int radix = radices[iCtr1];
                // Convert a value with a radix.
                String valueString = Convert.ToString(value, radix);
                Console.WriteLine("{0,13}  {1,3}    {2}",
                    System.Convert.ToString(value),
                    System.Convert.ToString(radix), valueString);
            }
        }
    } //RunToStringDemo   
   
   public static void main(String[] args)
   {
        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();
   } //main
} //ConvertRadixIntDemo

/*
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.

     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    7fffffff
*/

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

Show:
© 2014 Microsoft