C# Int16 MinValue

Description

Int16 MinValue represents the smallest possible value of Int16. This field is constant.

Syntax

Int16.MinValue has the following syntax.


public const short MinValue

Example

The following example uses the MinValue property to prevent an OverflowException when converting to an Int16 value.


//w  ww  .  j av  a 2 s  .  com
using System;
public class MainClass{
  public static void Main(String[] argv){  
    long[] numbersToConvert = {162345, 32183, -54000};
    short newNumber;
    foreach (long number in numbersToConvert)
    {
       if (number >= Int16.MinValue && number <= Int16.MaxValue)
       {
          newNumber = Convert.ToInt16(number);
          Console.WriteLine("Successfully converted {0} to an Int16.", 
                            newNumber);
       }
       else
       {
          Console.WriteLine("Unable to convert {0} to an Int16.", number);
       }
    }

  }
}
    

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