Int64:该结构用于表示 64 位有符号整数。Int64 可以存储两种类型的值,包括负值和正值,范围在 -9,223,372,036,854,775,808 到 +9、223,372,036,854,775,807 之间
例子:
// C# program to show the
// difference between Int64
// and UInt64
using System;
using System.Text;
public
class GeekdocsDemo {
// 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);
}
}
}运行结果:
Minimum value of Int64: -9223372036854775808
Maximum value of Int64: 9223372036854775807
-3
0
1
3
7UInt64: UInt64结构用于表示 64 位无符号整数。UInt64 只能存储范围从 0 到 18,446,744,073,709,551,615 的正值。
例子:
// C# program to show the
// difference between Int64
// and UInt64
using System;
using System.Text;
public class GeekdocsDemo{
// 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
7C#中Int64和UInt64的区别
| 序号 | INT64 | UINT64 |
|---|---|---|
| 1 | Int64 用于表示 64 位有符号整数。 | UInt64 用于表示 64 位无符号整数。 |
| 2 | Int64 代表有符号整数。 | UInt64 代表无符号整数。 |
| 3 | Int64可以存储负整数和正整数。 | UINT64只能存储正整数。 |
| 4 | Int64在内存中占用 8 字节空间。 | UINT64还占用内存中的 8 字节空间。 |
| 5 | Int64 的范围是从 -9223372036854775808 到 +9223372036854775807 。 | UInt64 的范围从 0 到 18446744073709551615。 |
| 6 | 声明 Int64 的语法: Int64 variable_name; | 声明 UInt64 的语法: UInt64 variable_name; |
