c# uint64
uint, UInt16, UInt32 and UInt64 are used to represent unsigned integers with values ranging based on their capacities/occupied size in the memory. These types work with positive values only. All these types are the same in nature but different based on the value ranges.
uint,UInt16,UInt32和UInt64用于表示无符号整数,其值的范围取决于其在内存中的容量/占用的大小。 这些类型仅适用于正值。 所有这些类型本质上都是相同的,但根据值范围而不同。
uint,UInt16,UInt32和UInt64之间的区别 (Difference between uint, UInt16, UInt32 and UInt64)
1)UInt16 (1) UInt16)
UInt16 represents 16-bits (2-bytes) unsigned integer.
UInt16表示16位(2字节)无符号整数。
UInt16 occupies 16-bits (2-bytes) space in the memory.
UInt16在内存中占用16位(2字节)的空间。
As per the 2-bytes data capacity, an UInt16's value capacity is 0 to +65535.
根据2字节的数据容量, UInt16的值容量为0到+65535。
Example:
例:
Consider the code – Here, we are printing required size, type, minimum & maximum value, variable declaration, and assignment of an UInt16.
考虑代码–在这里,我们正在打印所需的大小,类型,最小值和最大值,变量声明以及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 variables
UInt16 a = 12345;
UInt16 b = 65000;
Console.WriteLine("a = {0}, b = {1}", a, b);
//hit ENTER to exit
Console.ReadLine();
}
}
}
Output
输出量
UInt16 occupies 2 bytes
UInt16 type is: System.UInt16
UInt16 MIN value: 0
UInt16 MAX value: 65535
a = 12345, b = 65000
2)UInt32 / uint (2) UInt32/uint)
uint is an alias of UInt32, so, uint and UInt32 are the same type.
uint是UInt32的别名,因此uint和UInt32是同一类型。
UInt32 represents 32-bits (4-bytes) unsigned integer.
UInt32表示32位(4字节)无符号整数。
UInt32 occupies 32-bits (4-bytes) space in the memory.
UInt32在内存中占用32位(4字节)空间。
As per the 4-bytes data capacity, an UInt32's value capacity is 0 to +4294967295.
按照4字节的数据容量, UInt32的值容量为0到+4294967295。
Example:
例:
Consider the code – Here, we are printing required size, type, minimum & maximum value, variable declaration, and assignment of an UInt32 or uint.
考虑代码–在这里,我们正在打印所需的大小,类型,最小值和最大值,变量声明以及UInt32或uint的分配。
using System;
using System.Text;
namespace Test
{
class Program
{
static void Main(string[] args)
{
//printing UInt32 capacity, type, MIN & MAX value
Console.WriteLine("UInt32 occupies {0} bytes", sizeof(UInt32));
Console.WriteLine("UInt32 type is: {0}", typeof(UInt32));
Console.WriteLine("UInt32 MIN value: {0}", UInt32.MinValue);
Console.WriteLine("UInt32 MAX value: {0}", UInt32.MaxValue);
Console.WriteLine();
//UInt32 variables
UInt32 a = 289812345;
UInt32 b = 90909;
Console.WriteLine("a = {0}, b = {1}", a, b);
Console.WriteLine();
//printing uint capacity, type, MIN & MAX value
Console.WriteLine("uint occupies {0} bytes", sizeof(uint));
Console.WriteLine("uint type is: {0}", typeof(uint));
Console.WriteLine("uint MIN value: {0}", uint.MinValue);
Console.WriteLine("uint MAX value: {0}", uint.MaxValue);
Console.WriteLine();
//uint variables
uint x = 289812345;
uint y = 90909;
Console.WriteLine("x = {0}, y = {1}", x, y);
//hit ENTER to exit
Console.ReadLine();
}
}
}
Output
输出量
UInt32 occupies 4 bytes
UInt32 type is: System.UInt32
UInt32 MIN value: 0
UInt32 MAX value: 4294967295
a = 289812345, b = 90909
uint occupies 4 bytes
uint type is: System.UInt32
uint MIN value: 0
uint MAX value: 4294967295
x = 289812345, y = 90909
3)UInt64 (3) UInt64)
UInt64 represents 64-bits (8-bytes) unsigned integer.
UInt64表示64位(8字节)无符号整数。
UInt64 occupies 64-bits (8-bytes) space in the memory.
UInt64在内存中占用64位(8字节)的空间。
As per the 8-bytes data capacity, an UInt64's value capacity is 0to +18446744073709551615.
按照8字节的数据容量, UInt64的值容量为0到+18446744073709551615。
Example:
例:
Consider the code – Here, we are printing required size, type, minimum & maximum value, variable declaration, and assignment of an UInt64.
考虑代码–在这里,我们正在打印所需的大小,类型,最小值和最大值,变量声明以及UInt64的分配。
using System;
using System.Text;
namespace Test
{
class Program
{
static void Main(string[] args)
{
//printing UInt64 capacity, type, MIN & MAX value
Console.WriteLine("UInt64 occupies {0} bytes", sizeof(UInt64));
Console.WriteLine("UInt64 type is: {0}", typeof(UInt64));
Console.WriteLine("UInt64 MIN value: {0}", UInt64.MinValue);
Console.WriteLine("UInt64 MAX value: {0}", UInt64.MaxValue);
Console.WriteLine();
//UInt64 variables
UInt64 a = 289818278722345;
UInt64 b = 98983989;
Console.WriteLine("a = {0}, b = {1}", a, b);
Console.WriteLine();
//hit ENTER to exit
Console.ReadLine();
}
}
}
Output
输出量
UInt64 occupies 8 bytes
UInt64 type is: System.UInt64
UInt64 MIN value: 0
UInt64 MAX value: 18446744073709551615
a = 289818278722345, b = 98983989
翻译自: https://www.includehelp.com/dot-net/difference-between-uint-UInt16-UInt32-and-UInt64-in-c-sharp.aspx
c# uint64