Alex Rivera | Logout

Are Generic lists stored on the stack or the heap in C#?

Asked 2010-09-13T16:32:07.963
10

Are Generic lists stored on the stack Or the heap?

example

//List of Ints
List<int> myInts = new List<int>();
myInts.Add(5);
myInts.Add(10);
myInts.Add(20);

Is myInts stored on the stack or the heap? If I add an int to the list, does boxing or unboxing occur?

Edit
Report

1 Answer

0

For structs like int, the generic list is getting specialized and therefore no boxing/unboxing is required.

Note that the values themselves are stored in a backing array of the List nevertheless.

answered 2010-09-13T16:36:58.127

Your Answer