📜  C#中Int32和UInt32的区别

📅  最后修改于: 2021-09-14 02:33:59             🧑  作者: Mango

Int32 结构用于表示 32 位有符号整数。所述的Int32可存储两种类型的值,包括范围之间负的和正的-2147483648到2147483647。

例子 :

C#
// C# program to show the
// difference between Int32
// and UInt32
  
using System;
using System.Text;
  
public
class GFG {
  
  // Main Method
  static void Main(string[] args) {
  
    // printing minimum & maximum values
    Console.WriteLine("Minimum value of Int32: " 
                      + Int32.MinValue);
    Console.WriteLine("Maximum value of Int32: " 
                      + Int32.MaxValue);
    Console.WriteLine();
  
    // Int32 array
    Int32[] arr1 = {-3, 0, 1, 3, 7};
  
    foreach (Int32 i in arr1)
    { 
      Console.WriteLine(i);
    }
  }
}


C#
// C# program to show the 
// difference between Int32 
// and UInt32
  
using System;
using System.Text;
  
public class GFG{
      
    // Main Method
    static void Main(string[] args)
    {
  
        // printing minimum & maximum values
        Console.WriteLine("Minimum value of UInt32: "
                          + UInt32.MinValue);
        Console.WriteLine("Maximum value of UInt32: "
                          + UInt32.MaxValue);
        Console.WriteLine();
          
        // Int32 array
        UInt32[] arr1 = { 13, 0, 1, 3, 7};
          
        foreach (UInt32 i in arr1)
        {
            Console.WriteLine(i);
        }
    }
}


输出:

Minimum value of Int32: -2147483648
Maximum value of Int32: 2147483647

-3
0
1
3
7

UInt32 结构用于表示 32 位无符号整数。所述UInt32的只能存储唯一积极的值,其范围从0到4294967295。

例子 :

C#

// C# program to show the 
// difference between Int32 
// and UInt32
  
using System;
using System.Text;
  
public class GFG{
      
    // Main Method
    static void Main(string[] args)
    {
  
        // printing minimum & maximum values
        Console.WriteLine("Minimum value of UInt32: "
                          + UInt32.MinValue);
        Console.WriteLine("Maximum value of UInt32: "
                          + UInt32.MaxValue);
        Console.WriteLine();
          
        // Int32 array
        UInt32[] arr1 = { 13, 0, 1, 3, 7};
          
        foreach (UInt32 i in arr1)
        {
            Console.WriteLine(i);
        }
    }
}

输出:

Minimum value of UInt32: 0
Maximum value of UInt32: 4294967295

13
0
1
3
7

C#中Int32和UInt32的区别

Sr.No

INT32

UINT32

1.

Int32 is used to represents 32-bit signed integers . UInt32 is used to represent 32-bit unsigned integers.

2.

Int32 stands for signed integer. UInt32 stands for unsigned integer.

3.

It can store negative and positive integers. It can store only positive integers.

4.

It takes 4-bytes  space in the memory. It also takes 4-bytes space in the memory.

5.

The range of Int32 is from -2147483648 to +2147483647. The UInt32 ranges from 0 to 4294967295.

 6.

 Syntax to declare the Int32 :

Int32 variable_name;

  Syntax to declare the UInt32:

UInt32 variable_name;