SByte.MaxValue フィールド

定義

SByte の最大有効値を表します。Represents the largest possible value of SByte. このフィールドは定数です。This field is constant.

public: System::SByte MaxValue = 127;
public const sbyte MaxValue = 127;
val mutable MaxValue : sbyte
Public Const MaxValue As SByte  = 127

フィールド値

SByte

次の例では、 MinValue フィールドとフィールドを使用し MaxValue て、 Int64 SByte 型変換を実行する前に、値が型の範囲内にあることを確認します。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. この検証により、実行時にが発生しません OverflowExceptionThis 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       

注釈

この定数の値は127です。つまり、16進数の0x7F です。The value of this constant is 127; that is, hexadecimal 0x7F.

適用対象

こちらもご覧ください