Hi,
I have a method which returns an array of fixed type objects (let's say MyObject
).
The method creates a new empty Stack<MyObject>
. Then, it does some work and pushes some number of MyObjects
to the end of the Stack
. Finally, it returns the Stack.ToArray()
.
It does not change already added items or their properties, nor remove them. The number of elements to add will cost performance. There is no need to sort/order the elements.
Is Stack a best thing to use? Or must I switch to Collection
or List
to ensure better performance and/or lower memory cost?