Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In c# when an int is stored in a List<int> or int[] is that int still on the stack or is it boxed/moved to the heap?

Tags:

c#

.net

I understand int's, as are all value types, are stored on the stack. Int's can be boxed into objects which then means the int is storage on the heap. BUT what happens when an int is stored in a List or int[]?

I know List ofT is a class/reference type/heap stored type - does this mean int's in a List are boxed onto the heap?

Thanks

like image 318
JamesRedcoat Avatar asked Dec 12 '25 10:12

JamesRedcoat


1 Answers

No boxing is necessary when working with the generic List<int> type.

like image 168
Darin Dimitrov Avatar answered Dec 13 '25 22:12

Darin Dimitrov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!