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 鲜花英语祝福语卡片简短