This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

.NET Framework
.NET 1.1+

Numeric Types, MaxValue and MinValue

All of the basic numeric data types include two useful fields named MaxValue and MinValue. In this short article, these two properties are used to show the full range of values that can be held in each of the numeric types.

MaxValue and MinValue

All of the numeric data types expose the MaxValue and MinValue fields. These two members return the largest and smallest values that can be held within the data type without the possibility of generating an overflow exception. Each of the fields is read-only and is a static member of the numeric data type's structure.

The following code outputs the range of permissible values for each of the numeric types:

Console.WriteLine("byte\t{0} to {1}", byte.MinValue, byte.MaxValue);
Console.WriteLine("sbyte\t{0} to {1}", sbyte.MinValue, sbyte.MaxValue);
Console.WriteLine("short\t{0} to {1}", short.MinValue, short.MaxValue);
Console.WriteLine("ushort\t{0} to {1}", ushort.MinValue, ushort.MaxValue);
Console.WriteLine("int\t{0} to {1}", int.MinValue, int.MaxValue);
Console.WriteLine("uint\t{0} to {1}", uint.MinValue, uint.MaxValue);
Console.WriteLine("long\t{0} to {1}", long.MinValue, long.MaxValue);
Console.WriteLine("ulong\t{0} to {1}", ulong.MinValue, ulong.MaxValue);
Console.WriteLine("float\t{0} to {1}", float.MinValue, float.MaxValue);
Console.WriteLine("double\t{0} to {1}", double.MinValue, double.MaxValue);
Console.WriteLine("decimal\t{0} to {1}", decimal.MinValue, decimal.MaxValue);


byte    0 to 255
sbyte   -128 to 127
short   -32768 to 32767
ushort  0 to 65535
int     -2147483648 to 2147483647
uint    0 to 4294967295
long    -9223372036854775808 to 9223372036854775807
ulong   0 to 18446744073709551615
float   -3.402823E+38 to 3.402823E+38
double  -1.79769313486232E+308 to 1.79769313486232E+308
decimal -79228162514264337593543950335 to 79228162514264337593543950335

13 May 2008