UInt64.MinValue Field
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Represents the smallest possible value of UInt64. This field is constant.
public: System::UInt64 MinValue = 0;
public const ulong MinValue = 0;
val mutable MinValue : uint64
Public Const MinValue As ULong = 0
Value = 0
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;
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);
}
open System
let decimalValue = -1.5
// Discard fractional portion of Double value
let decimalInteger = floor decimalValue
if decimalInteger <= float UInt64.MaxValue && decimalInteger >= float UInt64.MinValue then
let integerValue = uint64 decimalValue
printfn $"Converted {decimalValue} to {integerValue}."
else
let rangeLimit, relationship =
if decimalInteger > float UInt64.MaxValue then
UInt64.MaxValue, "greater"
else
UInt64.MinValue, "less"
printfn $"Conversion failure: {decimalInteger} is {relationship} than {rangeLimit}."
Dim decimalValue As Double = -1.5
Dim integerValue As ULong
' Discard fractional portion of Double value
Dim decimalInteger As Double = Math.Floor(decimalValue)
If decimalInteger <= ULong.MaxValue AndAlso _
decimalInteger >= ULong.MinValue Then
integerValue = CULng(decimalValue)
Console.WriteLine("Converted {0} to {1}.", decimalValue, integerValue)
Else
Dim rangeLimit As ULong
Dim relationship As String
If decimalInteger > ULong.MaxValue Then
rangeLimit = ULong.MaxValue
relationship = "greater"
Else
rangeLimit = ULong.MinValue
relationship = "less"
End If
Console.WriteLine("Conversion failure: {0} is {1} than {2}", _
decimalInteger, _
relationship, _
rangeLimit)
End If
The value of this constant is 0.
Product | Versions |
---|---|
.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 |
.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 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: