首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

C# 基元類型與 FCL 對應關係深度解析(二):int/Int32/string/String 別名機制、隱含轉換與 IL 代碼驗證

     編輯:關於C語言

基元類型對應表

C# 關鍵字FCL 類型CLS-Compliant
sbyteSystem.SByteNo
byteSystem.ByteYes
shortSystem.Int16Yes
ushortSystem.UInt16No
intSystem.Int32Yes
uintSystem.UInt32No
longSystem.Int64Yes
ulongSystem.UInt64No
charSystem.CharYes
floatSystem.SingleYes
doubleSystem.DoubleYes
decimalSystem.DecimalYes
objectSystem.ObjectYes
stringSystem.StringYes

關鍵結論

  1. int 編譯後即為 System.Int32,四種宣告方式(int a=0; Int32 b=0; int c=new int(); System.Int32 d=new System.Int32();)產生完全相同的 IL。
  2. string 是 System.String 的編譯器別名,無實質差異。

using 別名視角理解


using sbyte = System.SByte;
using int = System.Int32;
using string = System.String;

隱含轉換 IL 驗證


Int32 i = 0;
Int64 j = i; // 隱含轉換
// IL: ldloc.0 → conv.i8 → stloc.1

雖 Int32、Int64 無繼承關係,但基元類型層級定義了安全的隱含/顯式轉換規則,編譯器插入 conv.i8 完成擴展轉換。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved