Boxing vs Unboxing

前端 未结 6 1903
暖寄归人
暖寄归人 2021-02-01 16:48

Another recent C# interview question I had was if I knew what Boxing and Unboxing is. I explained that value types are on Stack and reference types on Heap. When a value is cast

6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-01 17:08

    1. You're right the second assignment replaces the first. It doesn't change the boxed value.

    2. Your example doesn't make use of boxing. The value (int) is stored as an int and not boxed.

    3. No, boxing still keeps the immutability guarantee.

提交回复
热议问题