Mono Class Library: System.Int32 Overview | Members

System.Int32.ToString Method

Returns a string representation of the value of the current instance.

public string ToString (string format)

Parameters

format
A string that specifies the format of the returned string.
Note: For a list of valid values, see int.ToString(string, IFormatProvider).

Returns

A string representation of the current instance formatted as specified by format. The string takes into account the current system culture.

Exceptions

TypeReason
FormatExceptionformat is invalid.

Remarks

This method is equivalent to int.ToString(format, null).

If format is a null reference, the general format specifier "G" is used.

Example

This example demonstrates converting a int to a string.

C# Example

using System;
public class Int32ToStringExample {
   public static void Main() {
      Int32 i = 32;
      Console.WriteLine(i);
      String[] formats = {"c", "d", "e", "f", "g", "n", "p", "x" };
      foreach(String str in formats)
         Console.WriteLine("{0}: {1}", str, i.ToString(str));
   }
}

The output is

32
c: $32.00
d: 32
e: 3.200000e+001
f: 32.00
g: 32
n: 32.00
p: 3,200.00 %
x: 20

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0