英語で読む

次の方法で共有


UInt64.MaxValue フィールド

定義

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

C#
public const ulong MaxValue = 18446744073709551615;

フィールド値

Value = 18446744073709551615

次の例では、 MinValue フィールドと MaxValue フィールドを使用して、 Double 型変換を実行する前に値が型の UInt64 範囲内にあることを確認します。 これにより、実行時に が OverflowException 防止されます。

C#
double decimalValue = -1.5;
ulong integerValue; 

// Discard fractional portion of Double value
double decimalInteger = Math.Floor(decimalValue);

if (decimalInteger <= ulong.MaxValue && 
    decimalInteger >= ulong.MinValue)
{    
   integerValue = (ulong) decimalValue;
   Console.WriteLine("Converted {0} to {1}.", decimalValue, integerValue);
}   
else
{
   ulong rangeLimit;
   string relationship;
   
   if (decimalInteger > ulong.MaxValue)
   {
      rangeLimit = ulong.MaxValue;
      relationship = "greater";
   }   
   else
   {
      rangeLimit = ulong.MinValue;
      relationship = "less";
   }       

   Console.WriteLine("Conversion failure: {0} is {1} than {2}.",  
                     decimalInteger, 
                     relationship, 
                     rangeLimit);
}

注釈

この定数の値は 18,446,744,073,709,551,615 です。つまり、16 進数の0xFFFFFFFFFFFFFFFF。

適用対象

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

こちらもご覧ください