Re: Classes VS Structures
The vast majority of the types you create should be classes. Structures are faster to access because they are stored on the stack, but that also means that any time you assign the value of a variable containing a structure to another variable, you copy the entire object.
As a rule of thumb, value types should never be more than 16 bytes in size. A standard reference type variable is 4 bytes. An Integer is 4 bytes. A Long is 8 bytes. As such, if you were going to define a type with three fields: one a reference type (that includes String), one an Integer and one a Long, that would be as big as a structure should be. If you wanted to add another field then you should consider a class rather than a structure.
Structures should only be used to represent very simple type. In many cases, a structure contains just a single field and then the properties and method of the type interpret that one value. A classic example is the DateTime structure. Internally, its just a single number that occupies 8 bytes:
Quote:
Originally Posted by MSDN
Time values are measured in 100-nanosecond units called ticks, and a particular date is the number of ticks since 12:00 midnight, January 1, 0001 A.D. (C.E.) in the GregorianCalendar calendar. For example, a ticks value of 31241376000000000L represents the date, Friday, January 01, 0100 12:00:00 midnight. A DateTime value is always expressed in the context of an explicit or default calendar.
Generally, assume that new types that you create will be classes unless you have some specific reason for making them structures.
Re: Classes VS Structures
Ok thanks for the info JM.