C#中的int和Int32有什么区别?
Int32是.NET框架提供的类型,而int是C#语言中Int32的别名。
Int32x=5;
整数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
热门推荐
10 朋友新年祝福语大全 简短
11 新年祝福语简短大方兔年
12 搬新家礼物祝福语简短
13 同学见面花束祝福语简短
14 五一假期祝福语幽默简短
15 离职欢送敬酒祝福语简短
16 对学弟的祝福语简短
17 考老师辞职祝福语简短
18 祝福语驱散霉运的话简短