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 short.ToString(string) method formats an short 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 short.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 either a standard or a custom numeric format string. All standard numeric format strings other than "R" (or "r") are supported, as are all custom numeric format characters. If format is null or an empty string, the return value of this instance is formatted with the general numeric format specifier ("G").
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 formatting, see Formatting Types.
The return value of this instance is formatted with the System.Globalization.NumberFormatInfo for the current culture.
This example demonstrates converting a short to a string.
C# Example
using System;
public class Int16ToStringExample {
public static void Main() {
Int16 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