VB.NET - Structure Vs Class

Asked By Hrushikesh Pande on 27-Nov-09 02:30 AM
I want to use 3 string variables. Should I use structure or class for them?

Use Structure

Huggy Bear replied to Hrushikesh Pande on 27-Nov-09 02:32 AM
If you need to use only three string variables, then you can better go for Structure. Since a struncture is always light weight than a class.

You should consider these factors...

Michael Detras replied to Hrushikesh Pande on 27-Nov-09 03:59 AM

I once read from a book (MCTS Self-Paced Training Kit) that says that structures should meet all the following: 1. Represents a single value logically 2. Has an instance size that is less than 16 bytes 3. Is not frequently changed after creation and 4. Is not cast to a reference type.

The idea is to use a structure if that will perform better than using a class. For example, creating a large structure is not good if the structure is copied frequently. Hope this helps.