C#中的uint,UInt16,UInt32和UInt64之间的区别
uint,UInt16,UInt32和UInt64用于表示无符号整数,其值的范围取决于其在内存中的容量/占用的大小。这些类型仅适用于正值。所有这些类型本质上都是相同的,但是根据值范围而不同。
uint,UInt16,UInt32和UInt64之间的区别
1)UInt16
UInt16表示16位(2字节)无符号整数。
UInt16在内存中占用16位(2字节)的空间。
根据2字节的数据容量,UInt16的值容量为0到+65535。
示例
考虑代码–在这里,我们正在打印所需的大小,类型,最小值和最大值,变量声明以及UInt16的分配。
using System;
using System.Text;
namespace Test
{
class Program
{
static void Main(string[] args)
{
//printing UInt16 capacity, type, MIN & MAX value
Console.WriteLine("UInt16 occupies {0} bytes", sizeof(UInt16));
Console.WriteLine("UInt16 type is: {0}", typeof(UInt16));
Console.WriteLine("UInt16 MIN value: {0}", UInt16.MinValue);
Console.WriteLine("UInt16 MAX value: {0}", UInt16.MaxValue);
Console.WriteLine();
//UInt16变量
UInt16 a = 12345;
UInt16 b = 65000;
Console.WriteLine("a = {0}, b = {1}", a, b);
//按ENTER退出
Console.ReadLine();
}
}
}输出结果
UInt16 occupies 2 bytes UInt16 type is: System.UInt16 UInt16 MIN value: 0 UInt16 MAX value: 65535 a = 12345, b = 65000