c# int32和int_C#中的int,Int16,Int32和Int64之间的区别

c# int32和int

int, Int16, Int32 and Int64 are used to represent signed integers with values ranging based on their capacities/occupied size in the memory. These types are able to work with negative and positive values. All these types are the same in nature but different based on the value ranges.

int,Int16,Int32和Int64用于表示带符号整数,其值的范围取决于其在内存中的容量/占用的大小。 这些类型可以使用负值和正值。 所有这些类型本质上都是相同的,但根据值范围而不同。

int,Int16,Int32和Int64之间的区别 (Difference between int, Int16, Int32 and Int64)

1)Int16 (1) Int16)

  • Int16 represents 16-bits (2-bytes) signed integer.

    Int16表示16位(2字节)有符号整数。

  • Int16 occupies 16-bits (2-bytes) space in the memory.

    Int16在内存中占用16位(2字节)的空间。

  • As per the 2-bytes data capacity, an Int16's value capacity is -32768 to +32767.

    根据2字节的数据容量, Int16的值容量为-32768至+32767。

Example:

例:

Consider the code – Here, we are printing required size, type, minimum & maximum value, variable declaration, and assignment of an Int16.

考虑代码–在这里,我们正在打印所需的大小,类型,最小值和最大值,变量声明以及Int16的赋值。

using System;
using System.Text;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            //printing Int16 capacity, type, MIN & MAX value
            Console.WriteLine("Int16 occupies {0} bytes", sizeof(Int16));
            Console.WriteLine("Int16 type is: {0}", typeof(Int16));
            Console.WriteLine("Int16 MIN value: {0}", Int16.MinValue);
            Console.WriteLine("Int16 MAX value: {0}", Int16.MaxValue);
            Console.WriteLine();

            //Int16 variables
            Int16 a = 12345;
            Int16 b = -12345;
            Console.WriteLine("a = {0}, b = {1}", a, b);

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

Output

输出量

Int16 occupies 2 bytes
Int16 type is: System.Int16
Int16 MIN value: -32768
Int16 MAX value: 32767

a = 12345, b = -12345


2)Int32 /整数 (2) Int32/int)

int is an alias of Int32, so, int and Int32 are the same type.

int是Int32的别名,因此int和Int32是同一类型。

  • Int32 represents 32-bits (4-bytes) signed integer.

    Int32表示32位(4字节)有符号整数。

  • Int32 occupies 32-bits (4-bytes) space in the memory.

    Int32在内存中占用32位(4字节)空间。

  • As per the 4-bytes data capacity, an Int32's value capacity is -2147483648 to +2147483647.

    按照4字节的数据容量, Int32的值容量为-2147483648至+2147483647。

Example:

例:

Consider the code – Here, we are printing required size, type, minimum & maximum value, variable declaration, and assignment of an Int32 or int.

考虑代码–在这里,我们正在打印所需的大小,类型,最小值和最大值,变量声明以及Int32或int的赋值。

using System;
using System.Text;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            //printing Int32 capacity, type, MIN & MAX value
            Console.WriteLine("Int32 occupies {0} bytes", sizeof(Int32));
            Console.WriteLine("Int32 type is: {0}", typeof(Int32));
            Console.WriteLine("Int32 MIN value: {0}", Int32.MinValue);
            Console.WriteLine("Int32 MAX value: {0}", Int32.MaxValue);
            Console.WriteLine();

            //Int32 variables
            Int32 a = 289812345;
            Int32 b = -290012345;
            Console.WriteLine("a = {0}, b = {1}", a, b);
            Console.WriteLine();

            //printing int capacity, type, MIN & MAX value
            Console.WriteLine("int occupies {0} bytes", sizeof(int));
            Console.WriteLine("int type is: {0}", typeof(int));
            Console.WriteLine("int MIN value: {0}", int.MinValue);
            Console.WriteLine("int MAX value: {0}", int.MaxValue);
            Console.WriteLine();

            //int variables
            int x = 289812345;
            int y = -290012345;
            Console.WriteLine("x = {0}, y = {1}", x, y);

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

Output

输出量

Int32 occupies 4 bytes
Int32 type is: System.Int32
Int32 MIN value: -2147483648
Int32 MAX value: 2147483647

a = 289812345, b = -290012345

int occupies 4 bytes
int type is: System.Int32
int MIN value: -2147483648
int MAX value: 2147483647

x = 289812345, y = -290012345


3)Int64 (3) Int64)

  • Int64 represents 64-bits (8-bytes) signed integer.

    Int64表示64位(8字节)有符号整数。

  • Int64 occupies 64-bits (8-bytes) space in the memory.

    Int64在内存中占用64位(8字节)的空间。

  • As per the 8-bytes data capacity, an Int64's value capacity is -9223372036854775808 to +9223372036854775807.

    根据8字节数据容量, Int64的值容量为-9223372036854775808至+9223372036854775807。

Example:

例:

Consider the code – Here, we are printing required size, type, minimum & maximum value, variable declaration, and assignment of an Int64.

考虑代码–在这里,我们正在打印所需的大小,类型,最小值和最大值,变量声明以及Int64的分配。

using System;
using System.Text;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            //printing Int64 capacity, type, MIN & MAX value
            Console.WriteLine("Int64 occupies {0} bytes", sizeof(Int64));
            Console.WriteLine("Int64 type is: {0}", typeof(Int64));
            Console.WriteLine("Int64 MIN value: {0}", Int64.MinValue);
            Console.WriteLine("Int64 MAX value: {0}", Int64.MaxValue);
            Console.WriteLine();

            //Int64 variables
            Int64 a = 289818278722345;
            Int64 b = -290287827012345;
            Console.WriteLine("a = {0}, b = {1}", a, b);
            Console.WriteLine();

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

Output

输出量

Int64 occupies 8 bytes
Int64 type is: System.Int64
Int64 MIN value: -9223372036854775808
Int64 MAX value: 9223372036854775807

a = 289818278722345, b = -290287827012345


翻译自: https://www.includehelp.com/dot-net/difference-between-int-Int16-Int32-and-Int64-in-c-sharp.aspx

c# int32和int

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值