C# 中 int 和 Int32 有什么区别?
Int32是 .NET 框架提供的类型,而 int是C#语言中 Int32 的别名。
Int32 x = 5;
int x = 5;
因此,使用上述两种语句都会包含一个 32 位整数。它们编译为相同的代码,因此在执行时完全没有区别。
唯一细微的差别是 Int32 只能用于System 命名空间。在验证如上所述的值的类型时,我们可以使用 Int32 或 int。
typeof(int) == typeof(Int32) == typeof(System.Int32)
示例
以下示例展示了如何使用 System.Int32 声明整数。
using System;
namespace DemoApplication{
class Program{
static void Main(string[] args){
Int32 x = 5;
Console.WriteLine(x); //Output: 5
}
}
}输出
5
示例
以下示例展示了如何使用 int 关键字声明整数。
using System;
namespace DemoApplication{
class Program{
static void Main(string[] args){
int x = 5;
Console.WriteLine(x); //Output: 5
}
}
}输出
5
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP