Re: C# Struct vs Class



Actually when I only declare struct it keep this on stack. but when I
add this struct to any arraylist then it keeps those in Heap. Then it
already takes memory for reference.

So my assumption is if we use struct but keep reference for further use
then struct and class is same?

Any idea ?

Thanks to all for replying this.



Kevien Lee wrote:
//to reduce the memory size I have redeclared this in struct

The struct is alloc in stack,but the class was on the heap.still there
is same size,but you should consider the value type and ref type
boxing/unboxing operate,it is the most cost

.



Relevant Pages


Loading