uint16 int c#_C#中的Int16和UInt16之间的区别

uint16 int c#

C#Int16和C#UInt16 (C# Int16 and C# UInt16)

In C#, Int16 known as a signed integer of 2 bytes which can store both types of values including negative and positive between the ranges of -32768 to +32767.

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

UInt16 known as an unsigned integer of 2 bytes which can store only positive values between the ranges of 0 to 65535.

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

'Int16'和'UInt16'之间的区别 (Differences between 'Int16' and 'UInt16')

Int16UInt16
Int16 stands for signed integer.UInt16 stands for unsigned integer.
It's capacity to store the value is -32768 to +32767.It's capacity to store the value is 0 to 65535.
It can store negative and positive integers.It can store only positive integers.
It occupies 2-bytes space in the memory.It also occupies 2-bytes space in the memory.
Declaration syntax:
Int16 variable;
Declaration syntax:
UInt16 variable;
16位 UInt16
Int16代表有符号整数。 UInt16代表无符号整数。
它存储值的能力是-32768至+32767。 该值的存储容量为0到65535。
它可以存储负整数和正整数。 它只能存储正整数。
它在内存中占用2个字节的空间。 它还在内存中占用2字节的空间。
声明语法:
Int16变量;
声明语法:
UInt16变量;

Example:

例:

In this example, to explain the differences between Int16 and UInt16 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#中Int16和UInt16之间区别 ,我们将打印它们的最小值和最大值,同时还声明了两个数组– arr1是有符号整数类型,而arr2是无符号整数类型。 根据其容量用相应的负值和正值初始化数组。

using System;
using System.Text;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            //Int16 value range 
            Console.WriteLine("Int16 value capacity...");
            Console.WriteLine("Min: {0}, Max: {1}\n", Int16.MinValue, Int16.MaxValue);

            //UInt16 value range 
            Console.WriteLine("UInt16 value capacity...");
            Console.WriteLine("Min: {0}, Max: {1}\n", UInt16.MinValue, UInt16.MaxValue);

            //Int16 array
            Int16[] arr1 = { -32768, 0, 1000, 32000, 32767};
            Console.WriteLine("UInt16 array elements...");
            foreach (Int16 num in arr1)
            {
                Console.WriteLine(num);
            }
            Console.WriteLine();

            //UInt16 array
            UInt16[] arr2 = { 0, 100, 23000, 65000, 65525};
            Console.WriteLine("UInt16 array elements...");
            foreach (UInt16 num in arr2)
            {
                Console.WriteLine(num);
            }

            //hit ENTER to exit
            Console.ReadLine();
        }
    }
}

Output

输出量

Int16 value capacity...
Min: -32768, Max: 32767

UInt16 value capacity...
Min: 0, Max: 65535

UInt16 array elements...
-32768
0
1000
32000
32767

UInt16 array elements...
0
100
23000
65000
65525


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

uint16 int c#

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值