c# int uint32_C#中Int32和UInt32之间的区别

偏执的太偏执、 2023-03-05 15:49 298阅读 0赞

c# int uint32

C#Int32和C#UInt32 (C# Int32 and C# UInt32)

In C#, Int32 known as a signed integer of 4 bytes which can store both types of values including negative and positive between the ranges of -2147483648 to +2147483647.

在C#中, Int32被称为4字节的有符号整数,它可以存储-2147483648至+2147483647范围之间的两种类型的值,包括负数和正数。

UInt32 known as an unsigned integer of 4 bytes which can store only positive values between the ranges of 0 to 4294967295.

UInt32,它是4个字节的无符号整数 ,只能存储0到4294967295范围之间的正值。

‘Int32’和’UInt32’之间的区别 (Differences between ‘Int32’ and ‘UInt32’)




























Int32 UInt32
Int32 stands for signed integer. UInt32 stands for unsigned integer.
It’s capacity to store the value is -2147483648 to +2147483647. It’s capacity to store the value is 0 to 4294967295.
It can store negative and positive integers. It can store only positive integers.
It occupies 4-bytes space in the memory. It also occupies 4-bytes space in the memory.
Declaration syntax:
Int32 variable;
Declaration syntax:
UInt32 variable;



























32位 UInt32
Int32代表有符号整数。 UInt32代表无符号整数。
它存储值的能力是-2147483648至+2147483647。 该值的存储容量为0到4294967295。
它可以存储负整数和正整数。 它只能存储正整数。
它在内存中占用4个字节的空间。 它还在内存中占用4字节的空间。
声明语法:
Int32变量;
声明语法:
UInt32变量;

Example:

例:

In this example, to explain the differences between Int32 and UInt32 in C#, we are printing their minimum and maximum values, we are also declaring two arrays – arr1 is a signed integer type and arr2 is an unsigned integer type. Initializing the arrays with corresponding negative and positive values based on their capacity.

在此示例中,为了解释C#中Int32和UInt32之间区别 ,我们将打印它们的最小值和最大值,同时还声明了两个数组– arr1是有符号整数类型,而arr2是无符号整数类型。 根据其容量用相应的负值和正值初始化数组。

  1. using System;
  2. using System.Text;
  3. namespace Test
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. //Int32 value range
  10. Console.WriteLine("Int32 value capacity...");
  11. Console.WriteLine("Min: {0}, Max: {1}\n", Int32.MinValue, Int32.MaxValue);
  12. //UInt32 value range
  13. Console.WriteLine("UInt32 value capacity...");
  14. Console.WriteLine("Min: {0}, Max: {1}\n", UInt32.MinValue, UInt32.MaxValue);
  15. //Int32 array
  16. Int32[] arr1 = {
  17. -2147483648, 0, 12320009, 2147480000, 2147483647 };
  18. Console.WriteLine("UInt32 array elements...");
  19. foreach (Int32 num in arr1)
  20. {
  21. Console.WriteLine(num);
  22. }
  23. Console.WriteLine();
  24. //UInt32 array
  25. UInt32[] arr2 = {
  26. 0, 100, 23000, 4294960000, 4294967295 };
  27. Console.WriteLine("UInt32 array elements...");
  28. foreach (UInt32 num in arr2)
  29. {
  30. Console.WriteLine(num);
  31. }
  32. //hit ENTER to exit
  33. Console.ReadLine();
  34. }
  35. }
  36. }

Output

输出量

  1. Int32 value capacity...
  2. Min: -2147483648, Max: 2147483647
  3. UInt32 value capacity...
  4. Min: 0, Max: 4294967295
  5. UInt32 array elements...
  6. -2147483648
  7. 0
  8. 12320009
  9. 2147480000
  10. 2147483647
  11. UInt32 array elements...
  12. 0
  13. 100
  14. 23000
  15. 4294960000
  16. 4294967295

翻译自: https://www.includehelp.com/dot-net/Int32-and-UInt32-in-c-sharp.aspx

c# int uint32

发表评论

表情:
评论列表 (有 0 条评论,298人围观)

还没有评论,来说两句吧...

相关阅读

    相关 uint16,uint32是什么?

    记得之前在刷笔试题的时候就看见过这个问题,发现当时上网百度后又忘了。 最近在看CryEngine3引擎代码的时候又晕了,趁现在赶紧记下来~   在查看CE3的代码时我发现