首頁  >  文章  >  後端開發  >  C#中什麼是拆箱?

C#中什麼是拆箱?

WBOY
WBOY轉載
2023-09-12 13:13:11862瀏覽

C#中什麼是拆箱?

拳擊是隱式的,拆箱是顯式的。拆箱是將由裝箱建立的參考型別明確轉換回值型別。

讓我們來看一個C#中變數和物件的例子 −

// int
int x = 30;

// Boxing
object obj = x;

// Un boxing
int unboxInt = (int) obj;

以下是一個範例,展示了Un boxing −

int x = 5;
ArrayList arrList = new ArrayList();

// Boxing
arrList.Add(x);

// UnBoxing
int y = (int) arrList [0];
#

以上是C#中什麼是拆箱?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除