SByte.MinValue Champ

Définition

Représente la plus petite valeur possible de SByte. Ce champ est constant.

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

Valeur de champ

Value = -128

Exemples

L’exemple suivant utilise les MinValue champs et MaxValue pour vérifier qu’une Int64 valeur se trouve dans la plage du SByte type avant d’effectuer une conversion de type. Cette vérification empêche un au moment de l’exécution 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

Remarques

La valeur de cette constante est -128 ; autrement dit, 0x80 hexadécimaux.

S’applique à

Voir aussi