📜  C#中的Int64.MaxValue字段以及示例

📅  最后修改于: 2021-05-29 17:21:33             🧑  作者: Mango

Int64结构的MaxValue字段或属性用于表示Int64的最大值。该字段的值是常数,表示用户无法更改该字段的值。该字段的值为9223372036854775807。其十六进制值为0x7FFFFFFFFFFFFFFF

句法:

public const long MaxValue = 9223372036854775807;

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

例子:

// C# program to illustrate the
// Int64.MaxValue Field
using System;
  
class GFG {
      
    // Main Method
    static public void Main()
    {
        // display the Maximum
        // value of Int64 struct
        Console.WriteLine("Maximum Value is: "+
                            Int64.MaxValue);
          
        // taking a variable                 
        long var1 = 93422337368375807;
          
        if(var1.Equals(Int64.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: 9223372036854775807
Not equal..!!
Type of var1 is: Int64

参考:

  • https://docs.microsoft.com/zh-cn/dotnet/api/system.int64.maxvalue?view=netframework-4.7.2