อ่านในภาษาอังกฤษ แก้ไข

แชร์ผ่าน


SByte.MinValue Field

Definition

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

public const sbyte MinValue = -128;

Field Value

Value = -128

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.

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);
}

Remarks

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

Applies to

See also