From here
// The .NET Framework 2.0 way to create a list
List<int> list1 = new List<int>();
// No boxing, no casting:
list1.Add(3);
I understand there is no casting. But why no boxing happens?
"3" is on stack and list is in heap.
How it happens that value from stack moved to heap without boxing?
What happens under the hood?
Boxing doesn't happen here because the array that backs the List is T[]
, not object[]
. Therefore, the runtime knows your items are integers and doesn't need to box them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With