Leer en inglés

Compartir a través de


Int16.MinValue Campo

Definición

Representa el menor valor posible de Int16. Este campo es constante.

C#
public const short MinValue = -32768;

Valor de campo

Value = -32768

Ejemplos

En el ejemplo siguiente se usa la MinValue propiedad para evitar que se OverflowException convierta en un Int16 valor .

C#
long[] numbersToConvert = {162345, 32183, -54000};
short newNumber;
foreach (long number in numbersToConvert)
{
   if (number >= Int16.MinValue && number <= Int16.MaxValue)
   {
      newNumber = Convert.ToInt16(number);
      Console.WriteLine($"Successfully converted {newNumber} to an Int16.");
   }
   else
   {
      Console.WriteLine($"Unable to convert {number} to an Int16.");
   }
}
// The example displays the following output to the console:
//       Unable to convert 162345 to an Int16.
//       Successfully converted 32183 to an Int16.
//       Unable to convert -54000 to an Int16.

Comentarios

El valor de esta constante es -32768; es decir, 0x8000 hexadecimal.

La MinValue propiedad se usa normalmente para evitar que OverflowException se convierta de un tipo numérico con un intervalo inferior mayor (como o Int32 ) Int64en un Int16. En el ejemplo se muestra este uso.

Se aplica a

Producto Versiones
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

Consulte también