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 好听的元旦简短祝福语