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.