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