C#中long和int之间的区别? [英] Difference between long and int in C#?

查看:698
本文介绍了C#中long和int之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中, long int 之间的实际区别是什么?我知道在C / C ++中,在某些64位平台上(当然取决于操作系统),它的长度可能是64位,但是在C#中,它们都在.NET运行时中运行,所以有实际区别吗?

What is the actual difference between a long and an int in C#? I understand that in C/C++ long would be 64bit on some 64bit platforms(depending on OS of course) but in C# it's all running in the .NET runtime, so is there an actual distinction?

另一个问题: int 是否可以持有 long (通过强制转换)而不会在所有平台上丢失数据?

Another question: can an int hold a long(by cast) without losing data on all platforms?

推荐答案

一个 int (在运行时中也称为 System.Int32 )在任何平台上始终为带符号的32位整数,长度为 long (在任何平台上,aka System.Int64 )始终是一个带符号的64位整数。因此,您不能从 long 且其值小于 Int32.MaxValue 或小于的类型进行转换Int32.MinValue 而不会丢失数据。

an int (aka System.Int32 within the runtime) is always a signed 32 bit integer on any platform, a long (aka System.Int64) is always a signed 64 bit integer on any platform. So you can't cast from a long with a value above Int32.MaxValue or below Int32.MinValuewithout losing data.

这篇关于C#中long和int之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆