Mono Class Library: System.UInt16 Overview | Members

System.UInt16.ToString Method

Returns a string representation of the value of the current instance. [Edit]

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 ushort.ToString(string, IFormatProvider).
[Edit]

Returns

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

Exceptions

TypeReason
FormatExceptionformat is invalid. [Edit]

Remarks

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

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

[Edit]

Example

This example demonstrates converting a ushort to a string.

C# Example
using System;
public class UInt16ToStringExample {
   public static void Main() {
      UInt16 i = 16;
      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

16
c: $16.00
d: 16
e: 1.600000e+001
f: 16.00
g: 16
n: 16.00
p: 1,600.00 %
x: 10

Requirements

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