C#中的Int64和UInt64之间的区别
C#Int64和C#UInt64
在C#中,Int64被称为8字节的有符号整数,它可以存储-9223372036854775808到+9223372036854775807范围之间的两种类型的值,包括负数和正数。
UInt64,它是8个字节的无符号整数,只能存储0到18446744073709551615615范围之间的正值。
“Int64”和“UInt64”之间的区别
Int64variable;
UInt64variable;
示例
在此示例中,为了解释C#中Int64和UInt64之间的区别,我们将打印它们的最小值和最大值,同时还声明了两个数组–arr1是有符号整数类型,而arr2是无符号整数类型。根据其容量用相应的负值和正值初始化数组。
using System;
using System.Text;
namespace Test
{
class Program
{
static void Main(string[] args)
{
//Int64值范围
Console.WriteLine("Int64 value capacity...");
Console.WriteLine("Min: {0}, Max: {1}\n", Int64.MinValue, Int64.MaxValue);
//UInt64值范围
Console.WriteLine("UInt64 value capacity...");
Console.WriteLine("Min: {0}, Max: {1}\n", UInt64.MinValue, UInt64.MaxValue);
//Int64数组
Int64[] arr1 = {
-9223372036854775808,
0,
1287822320009,
9223372036854700000,
9223372036854775807
};
Console.WriteLine("UInt64 array elements...");
foreach (Int64 num in arr1)
{
Console.WriteLine(num);
}
Console.WriteLine();
//UInt64数组
UInt64[] arr2 = {
0,
1239289300,
2399900900022,
18446744073709000000,
1844674407370955161
};
Console.WriteLine("UInt64 array elements...");
foreach (UInt64 num in arr2)
{
Console.WriteLine(num);
}
//按ENTER退出
Console.ReadLine();
}
}
}输出结果
Int64 value capacity... Min: -9223372036854775808, Max: 9223372036854775807 UInt64 value capacity... Min: 0, Max: 18446744073709551615 UInt64 array elements... -9223372036854775808 0 1287822320009 9223372036854700000 9223372036854775807 UInt64 array elements... 0 1239289300 2399900900022 18446744073709000000 1844674407370955161