What are structures and Enum used for?

Cheetah

Well-known member
Joined
Oct 12, 2006
Messages
232
Programming Experience
Beginner
Hi there,

I have seen uses of these before and i understand then, its just i don't know the "actual" use for them?

Could anyone explain them quickly for me?

Thanks.
 
Enumerations are used when you want a variable type that can be an integer that has a description.

Structures are a way of organizing data like a class, except it's not a class. Personally I use classes unless I explicitly need to use a structure.
 
Structures are generally smaller and less complex than a class, and are to be used for short-scoped periods (something that should "disappear" after it has been used), whereas a class is best suited for a "100% duty cycle" (something that should stay an object until told otherwise).

From a usage standpoint, there is very little difference between a class and a structure, however, a structure does not support inheritance, but can implement an interface.

From a technical standpoint, a class is a reference (reference types are stored on the heap) and a structure is a value (value types are stored on the stack).

As for when to use one or another; a structure would be suitable for passing event arguments back to a recipient class where there is only one "hop". A class would be better suited if these same event arguments would be passed onto other objects.

Enums, as stated, are basically a single variable with an array of possible assignable values described in text with an assigned number.
 
Last edited:
Back
Top