SByte.MaxValue 필드

정의

SByte의 가능한 최대값을 나타냅니다. 이 필드는 상수입니다.

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

필드 값

Value = 127

예제

다음 예제에서는 및 필드를 사용하여 MinValue 값이 형식 변환을 Int64 수행하기 전에 형식 범위 SByte 내에 있는지 확인 MaxValue 합니다. 이 확인은 런타임에 을 OverflowException 방지합니다.

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);
}
let longValue = -130L

if longValue <= int64 SByte.MaxValue && longValue >= int64 SByte.MinValue then
    let byteValue = int8 longValue
    printfn $"Converted long integer value to {byteValue}."
else
    let rangeLimit, relationship =
        if longValue > int64 SByte.MaxValue then
            SByte.MaxValue, "greater"
        else
            SByte.MinValue, "less"

    printfn $"Conversion failure: {longValue:n0} is {relationship} than {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.

적용 대상

추가 정보