SByte.MinValue 欄位

定義

代表 SByte 最小的可能值。Represents the smallest possible value of SByte. 這個欄位為常數。This field is constant.

public: System::SByte MinValue = -128;
public const sbyte MinValue = -128;
val mutable MinValue : sbyte
Public Const MinValue As SByte  = -128

欄位值

SByte

範例

下列範例 MinValue MaxValue 會在執行類型轉換之前,使用和欄位來確認 Int64 值是否在類型的範圍內 SByteThe 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. 這種驗證會防止 OverflowException 在執行時間發生。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);
}   
else
{
   sbyte rangeLimit;
   string relationship;
   
   if (longValue > sbyte.MaxValue)
   {
      rangeLimit = sbyte.MaxValue;
      relationship = "greater";
   }   
   else
   {
      rangeLimit = sbyte.MinValue;
      relationship = "less";
   }       

   Console.WriteLine("Conversion failure: {0:n0} is {1} than {2}.",  
                     longValue, 
                     relationship, 
                     rangeLimit);
}       
Dim longValue As Long = -130
Dim byteValue As SByte 

If longValue <= SByte.MaxValue AndAlso _
   longValue >= SByte.MinValue Then
   byteValue = CSByte(longValue)
   Console.WriteLine("Converted long integer value to {0}.", byteValue)
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       

   Console.WriteLine("Conversion failure: {0:n0} is {1} than {2}.", _ 
                     longValue, _
                     relationship, _
                     rangeLimit)
End If       

備註

這個常數的值為-128;亦即,十六進位0x80。The value of this constant is -128; that is, hexadecimal 0x80.

適用於

另請參閱