I know that one of the differences between classes and structs is that struct instances get stored on stack and class instances(objects) are stored on the heap.
Since classes and structs are very similar. Does anybody know the difference for this particular distinction?
(edited to cover points in comments)
To emphasise: there are differences and similarities between value-types and reference-types, but those differences have nothing to do with stack vs heap, and everything to do with copy-semantics vs reference-semantics. In particular, if we do:
Then are “first” and “second” talking about the same copy of
Foo? or different copies? It just so happens that the stack is a convenient and efficient way of handling value-types as variables. But that is an implementation detail.(end edit)
Re the whole “value types go on the stack” thing… – value types don’t always go on the stack;
then they go on the heap (the last two are actually just exotic examples of the first)
i.e.
Additionally, Eric Lippert (as already noted) has an excellent blog entry on this subject