英語で読む

次の方法で共有


Int16.MinValue フィールド

定義

Int16 の最小有効値を表します。 このフィールドは定数です。

C#
public const short MinValue = -32768;

フィールド値

Value = -32768

次の例では、 プロパティをMinValue使用して、 を値に変換するときに をInt16防ぎますOverflowException

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.

注釈

この定数の値は -32768 です。つまり、16 進数の0x8000。

プロパティはMinValue通常、より小さい範囲の数値型 (や などInt32) Int16から に変換するときに をInt64防ぐためにOverflowException使用されます。 この例では、この使用方法を示します。

適用対象

製品 バージョン
.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

こちらもご覧ください