📜  C#中的UInt64.MaxValue字段(带示例)

📅  最后修改于: 2021-05-29 22:18:19             🧑  作者: Mango

UInt64 Struct的MaxValue字段用于表示64位无符号长整数的最大值。该字段的值是常数,表示用户无法更改该字段的值。该字段的值为18446744073709551615。其十六进制值为0xFFFFFFFFFFFFFFFFFF 。它用于避免在运行时发生OverflowException。

句法:

public const ulong MaxValue = 18446744073709551615;

返回值:该字段始终返回18446744073709551615。

例子:

// C# program to illustrate the
// UInt64.MaxValue Field
using System;
  
class GFG {
  
    // Main Method
    static public void Main()
    {
        // display the Maximum
        // value of UInt64 struct
        Console.WriteLine("Maximum Value is: " + UInt64.MaxValue);
  
        // taking a variable
        ulong var1 = 93422337368375807;
  
        if (var1.Equals(UInt64.MaxValue))
        {
            Console.WriteLine("Equal..!!");
            Console.WriteLine("Type of var1 is: {0}",
                                 var1.GetTypeCode());
        }
  
        else 
        {
            Console.WriteLine("Not equal..!!");
            Console.WriteLine("Type of var1 is: {0}",
                                 var1.GetTypeCode());
        }
    }
}

输出:

Maximum Value is: 18446744073709551615
Not equal..!!
Type of var1 is: UInt64

参考:

  • https://docs.microsoft.com/zh-cn/dotnet/api/system.uint64.maxvalue?view=netstandard-2.1