📜  C#中的Int16和UInt16之间的区别

📅  最后修改于: 2021-05-30 00:17:46             🧑  作者: Mango

Int16 结构用于表示16位带符号整数。所述的Int16可存储两种类型的值,包括范围之间负的和正的-32768到32767。

例子 :

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


C#
// C# program to show the 
// difference between Int16 
// and UInt16
  
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);
        }
    }
}


输出:

Minimum value of Int16: -32768
Maximum value of Int16: 32767

-3
0
1
3
7

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

例子 :

C#

// C# program to show the 
// difference between Int16 
// and UInt16
  
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);
        }
    }
}

输出:

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

13
0
1
3
7

C#中的Int16和UInt16之间的区别

Sr.No

INT16

UINT16

1.

Int16 is used to represents 16-bit signed integer.s  UInt16 is used to represent 16-bit unsigned integers

2.

Int16 stands for signed integer. UInt16 stands for unsigned integer.

3.

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

4.

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

5.

The range of Int16 is from -32768 to +32767. The UInt16 ranges from 0 to 65535.

 6.

 Syntax to declare the Int16 :

Int16 variable_name;

  Syntax to declare the UInt16 :

UInt16 variable_name;