Windows Dev Center

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

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;
   outputBlock.Text += String.Format("Converted long integer value to {0}.", byteValue) + "\n";
}
else
{
   sbyte rangeLimit;
   string relationship;

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

   outputBlock.Text += String.Format("Conversion failure: {0:n0} is {1} than {2}.",
                     longValue,
                     relationship,
                     rangeLimit) + "\n";
}


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2015 Microsoft