C# Convert ToInt16(Object, IFormatProvider)

Description

Convert ToInt16(Object, IFormatProvider) converts the value of the specified object to a 16-bit signed integer, using the specified culture-specific formatting information.

Syntax

Convert.ToInt16(Object, IFormatProvider) has the following syntax.


public static short ToInt16(
  Object value,
  IFormatProvider provider
)

Parameters

Convert.ToInt16(Object, IFormatProvider) has the following parameters.

  • value - An object that implements the IConvertible interface.
  • provider - An object that supplies culture-specific formatting information.

Returns

Convert.ToInt16(Object, IFormatProvider) method returns A 16-bit signed integer that is equivalent to value, or zero if value is null.

Example


using System;// w  ww  .j a  va  2  s .com
using System.Globalization;

class MainClass
{
    public static void Main( )
    {
        NumberFormatInfo provider = new NumberFormatInfo();

        provider.NegativeSign = "neg ";
        provider.PositiveSign = "pos ";

        provider.NumberDecimalSeparator = ".";
        provider.NumberGroupSeparator = ",";
        provider.NumberGroupSizes = new int[ ] { 3 };
        provider.NumberNegativePattern = 0;

        Console.WriteLine( Convert.ToInt16((object) "12345" ));
        Console.WriteLine( Convert.ToInt16((object) "12345", provider ) );
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version