System.SByte.ToString Method

Converts the numeric value of this instance to its equivalent string representation, using the specified format.

Syntax

public string ToString (string format)

Parameters

format
A standard or custom numeric format string.

Returns

The string representation of the value of this instance as specified by format.

Exceptions

TypeReason
FormatException format is invalid.

Remarks

The sbyte.ToString(string) method formats an sbyte value in a specified format by using 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 sbyte.ToString(string) method, as follows:

Default ("G") format

Default (current) culture

sbyte.ToString

Default ("G") format

A specific culture

sbyte.ToString(IFormatProvider)

A specific format

A specific culture

sbyte.ToString(string, IFormatProvider)

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 sbyte 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:

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 negative sign, 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 sbyte.ToString(string, IFormatProvider) overload.

Example

This example demonstrates the sbyte.ToString(string) method.

C# Example

using System;
public class SByteToStringExample {
   public static void Main() {
      SByte i = 8;
      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

8
c: $8.00
d: 8
e: 8.000000e+000
f: 8.00
g: 8
n: 8.00
p: 800.00 %
x: 8

Requirements

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