Boxing vs Unboxing

前端 未结 6 1976
暖寄归人
暖寄归人 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:07

    b is still 1 because b is a reference that still points to the object on the heap with a value of 1. a is 2 because you assigned it to a new object on the heap with a value of 2.

    t2.x is 3 because t and t2 are two different references to the same object on the heap.

提交回复
热议问题