This topic has not yet been rated - Rate this topic

UInt64.MaxValue Field

April 12, 2014

Represents the largest possible value of UInt64. This field is constant.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
public const ulong MaxValue

The value of this constant is 18,446,744,073,709,551,615; that is, hexadecimal 0xFFFFFFFFFFFFFFFF.

The following example uses the MinValue and MaxValue fields to verify that a Double value is within the range of the UInt64 type before it performs a type conversion. This prevents an OverflowException at run time.


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;
   outputBlock.Text += String.Format("Converted {0} to {1}.", decimalValue, integerValue) + "\n";
}
else
{
   ulong rangeLimit;
   string relationship;

   if (decimalInteger > ulong.MaxValue)
   {
      rangeLimit = ulong.MaxValue;
      relationship = "greater";
   }
   else
   {
      rangeLimit = ulong.MinValue;
      relationship = "less";
   }

   outputBlock.Text += String.Format("Conversion failure: {0} is {1} than {2}.",
                     decimalInteger,
                     relationship,
                     rangeLimit) + "\n";
}


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.