📜  C#中Int64和UInt64的区别

📅  最后修改于: 2021-09-14 02:32:27             🧑  作者: Mango

Int64 Struct 用于表示 64 位有符号整数。所述的Int64可以两种类型的值,包括-9,223,372,036,854,775,808范围之间负的和正的存储9,223,372,036,854,775,807

例子 :

C#
// C# program to show the
// difference between Int64
// and UInt64
  
using System;
using System.Text;
  
public
class GFG {
  
  // Main Method
  static void Main(string[] args) {
  
    // printing minimum & maximum values
    Console.WriteLine("Minimum value of Int64: " 
                      + Int64.MinValue);
    Console.WriteLine("Maximum value of Int64: " 
                      + Int64.MaxValue);
    Console.WriteLine();
  
    // Int64 array
    Int64[] arr1 = {-3, 0, 1, 3, 7};
  
    foreach (Int64 i in arr1)
    { 
      Console.WriteLine(i);
    }
  }
}


C#
// C# program to show the 
// difference between Int64 
// and UInt64
  
using System;
using System.Text;
  
public class GFG{
      
    // Main Method
    static void Main(string[] args)
    {
  
        //printing minimum & maximum values
        Console.WriteLine("Minimum value of UInt64: "
                          + UInt64.MinValue);
        Console.WriteLine("Maximum value of UInt64: "
                          + UInt64.MaxValue);
        Console.WriteLine();
          
        //Int64 array
        UInt64[] arr1 = { 13, 0, 1, 3, 7};
          
        foreach (UInt64 i in arr1)
        {
            Console.WriteLine(i);
        }
    }
}


输出:

Minimum value of Int64: -9223372036854775808
Maximum value of Int64: 9223372036854775807

-3
0
1
3
7

UInt64 结构用于表示 64 位无符号整数。所述UINT64只能存储唯一积极的值,其范围为0〜18,446,744,073,709,551,615。

例子 :

C#

// C# program to show the 
// difference between Int64 
// and UInt64
  
using System;
using System.Text;
  
public class GFG{
      
    // Main Method
    static void Main(string[] args)
    {
  
        //printing minimum & maximum values
        Console.WriteLine("Minimum value of UInt64: "
                          + UInt64.MinValue);
        Console.WriteLine("Maximum value of UInt64: "
                          + UInt64.MaxValue);
        Console.WriteLine();
          
        //Int64 array
        UInt64[] arr1 = { 13, 0, 1, 3, 7};
          
        foreach (UInt64 i in arr1)
        {
            Console.WriteLine(i);
        }
    }
}

输出:

Minimum value of UInt64: 0
Maximum value of UInt64: 18446744073709551615

13
0
1
3
7

C#中Int64和UInt64的区别

Sr.No

INT64

UINT64

1.

Int64 is used to represents 64-bit signed integers . UInt64 is used to represent 64-bit unsigned integers.

2.

Int64 stands for signed integer. UInt64 stands for unsigned integer.

3.

It can store negative and positive integers. It can store only positive integers.

4.

It takes 8-bytes  space in the memory. It also takes 8-bytes space in the memory.

5.

The range of Int64 is from -9223372036854775808 to +9223372036854775807. The UInt64 ranges from 0 to 18446744073709551615.

 6.

 Syntax to declare the Int64 :

Int64 variable_name;

  Syntax to declare the UInt64:

UInt64 variable_name;