When to use struct and when to use class

C

Chris Dunaway

When deciding to use a structure or a class, what is the general "rule
of thumb"? When you're creating your data model, what factors
dictate that you use a class instead of a structure?

Structures are more lightweight than classes but for example if you're
only going to create a single instance (for whatever reason), it seems
that the added "weight" of a class would be negligible. If creating
many such instances, it might be different.

Is there any GC related issues when creating structures as opposed to
classes?

I'm just looking for a good rule of thumb on when to create structures
and when to create classes.
 
G

Guest

Hi,

Structures are value type and does not support inheritance. As a difference
between structures and classes, I feel that since the memory to be consumed
is in stack we should use structures for creating light weighted object.
Whereas, for the classes, they are reference type and since memory in heap is
much more than that in stack, we should use the classes for creating the
higher objects.GC works only with the classes and not with the structures. I
hope it helps you

regards
Nishith Pathak
http://dotnetpathak.blogspot.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top