MaxValue Field
Collapse the table of content
Expand the table of content

SByte.MaxValue Field


Represents the largest possible value of SByte. This field is constant.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

public const sbyte MaxValue

Field Value

Type: System.SByte

The value of this constant is 127; that is, hexadecimal 0x7F.

The following example uses the MinValue and MaxValue fields to verify that an Int64 value is within the range of the SByte type before it performs a type conversion. This verification prevents an OverflowException at run time.

long longValue = -130;
sbyte byteValue; 

if (longValue <= sbyte.MaxValue && 
    longValue >= sbyte.MinValue)
   byteValue = (sbyte) longValue;
   Console.WriteLine("Converted long integer value to {0}.", byteValue);
   sbyte rangeLimit;
   string relationship;

   if (longValue > sbyte.MaxValue)
      rangeLimit = sbyte.MaxValue;
      relationship = "greater";
      rangeLimit = sbyte.MinValue;
      relationship = "less";

   Console.WriteLine("Conversion failure: {0:n0} is {1} than {2}.",  

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
© 2015 Microsoft