共用方式為


SByte.MinValue Field

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

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

Syntax

'Declaration
Public Const MinValue As SByte
public const sbyte MinValue

Remarks

The value of this constant is -128; that is, hexadecimal 0x80.

Examples

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.

Dim longValue As Long = -130
Dim byteValue As SByte

If longValue <= SByte.MaxValue AndAlso _
   longValue >= SByte.MinValue Then
   byteValue = CSByte(longValue)
   outputBlock.Text += String.Format("Converted long integer value to {0}.", byteValue) + vbCrLf
Else
   Dim rangeLimit As SByte
   Dim relationship As String

   If longValue > SByte.MaxValue Then
      rangeLimit = SByte.MaxValue
      relationship = "greater"
   Else
      rangeLimit = SByte.MinValue
      relationship = "less"
   End If

   outputBlock.Text += String.Format("Conversion failure: {0:n0} is {1} than {2}.", _
                     longValue, _
                     relationship, _
                     rangeLimit) + vbCrLf
End If
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";
}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.