Ler em inglês

Compartilhar via


SByte.MaxValue Campo

Definição

Representa o maior valor possível de SByte. Este campo é constante.

C#
public const sbyte MaxValue = 127;

Valor do campo

Value = 127

Exemplos

O exemplo a seguir usa os MinValue campos e MaxValue para verificar se um Int64 valor está dentro do intervalo do tipo antes de SByte executar uma conversão de tipo. Essa verificação impede um em tempo de execução OverflowException .

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

Comentários

O valor dessa constante é 127; ou seja, 0x7F hexadecimais.

Aplica-se a

Produto Versões
netframework-4.6 netframework-4.6

Confira também