int 與 Int32 有何不同?string 與 String 有何不同?
int a = 0;
Int32 b = 0;
int c = new int();
System.Int32 d = new System.Int32();
.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
.maxstack 1
.locals init ([0] int32 a, [1] int32 b, [2] int32 c, [3] int32 d)
IL_0000: nop
IL_0001: ldc.i4.0
IL_0002: stloc.0
IL_0003: ldc.i4.0
IL_0004: stloc.1
IL_0005: ldc.i4.0
IL_0006: stloc.2
IL_0007: ldc.i4.0
IL_0008: stloc.3
IL_0009: ret
}
C# 關鍵字(int、string 等)僅是 FCL 類型(System.Int32、System.String)的編譯器別名,編譯後無任何差異。了解此機制有助於面試與深入理解類型系統,但日常開發使用習慣關鍵字即可。