📜  C#中的UInt16,UInt32和UInt64之间的区别

📅  最后修改于: 2021-05-29 16:36:14             🧑  作者: Mango

UInt16 结构用于表示16位无符号整数。 U Int16只能存储0到65535之间的正值。

例子 :

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


C#
// C# program to show the 
// UInt32 struct
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);
        }
    }
}


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


输出:

Minimum value of UInt16: 0
Maximum value of UInt16: 65535

13
0
1
3
7

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

例子 :

C#

// C# program to show the 
// UInt32 struct
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

UInt64 结构用于表示64位无符号整数。所述UINT64只能存储唯一积极的值,其范围为0〜18,446,744,073,709,551,615。

例子 :

C#

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

输出:

Minimum value of UInt64: 0
Maximum value of UInt64: 18446744073709551615

13
0
1
3
7

C#中的UInt16,UInt32和UInt64之间的区别

Sr.No

UINT16

UINT32

UINT64

1.

UInt16 is used to represent 16-bit unsigned integers UInt32 is used to represent 32-bit unsigned integers. UInt64 is used to represent 64-bit unsigned integers.

2.

UInt16 stands for unsigned integer. UInt32 also stands for unsigned integer. UInt64 also stands for unsigned integer.

3.

It can store only positive integers. It can also store only positive integers. It can also store only positive integers.

4.

It takes 2-bytes  space in the memory. It takes 4-bytes  space in the memory. It takes 8-bytes space in the memory.

5.

The UInt16 ranges from 0 to 65535. The UInt32 ranges from 0 to 4294967295. The UInt64 ranges from 0 to 18446744073709551615.

 6.

 Syntax to declare the UInt16:

UInt16 variable_name;

 Syntax to declare the UInt32:

UInt32 variable_name;

 Syntax to declare the UInt64:

UInt64 variable_name;