Converts the numeric value of this instance to its equivalent string representation using the specified format.
The string representation of the value of this instance as specified by format.
Type Reason FormatException format is invalid.
The uint.ToString(string) method formats a uint value in a specified format by using a System.Globalization.NumberFormatInfo object that represents the conventions of the current culture. If you want to use the default ("G", or general) format or specify a different culture, use the other overloads of the uint.ToString(string) method, as follows:
Default ("G") format |
Default (current) culture | |
Default ("G") format |
A specific culture | |
A specific format |
A specific culture |
The format parameter can be any valid standard numeric format specifier, or any combination of custom numeric format specifiers. If format is equal to string.Empty or is null, the return value of the current uint object is formatted with the general format specifier ("G"). If format is any other value, the method throws a FormatException.
The .NET Framework provides extensive formatting support, which is described in greater detail in the following formatting topics:
For more information about numeric format specifiers, see Standard Numeric Format Strings and Custom Numeric Format Strings.
For more information about support for formatting in the .NET Framework, see Formatting Types.
The format of the returned string is determined by the System.Globalization.NumberFormatInfo object for the current culture. Depending on the format parameter, this object controls symbols such as the group separator and the decimal point symbol in the output string. To provide formatting information for cultures other than the current culture, call the uint.ToString(string, IFormatProvider) overload.
This example demonstrates converting a uint to a string.
C# Example
using System; public class UInt32ToStringExample { public static void Main() { UInt32 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