Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Structures

Status
Not open for further replies.

elziko

Programmer
Nov 7, 2000
486
0
0
GB
Since Structures seem to have many of the features of a Class (methods/events etc), under what circumstances should I be using a Structure instead of a Class, or indeed vice versa?

Cheers

elziko
 
Hi Elziko!

Think of a structure as a lightweight class.

It's a value type (memory comes from the stack), whereas a class is a reference type (the pointer to the class comes from the stack, but memory for the guts of the class come from the heap).

While you can add methods and such to a structure, I myself don't see that as a good use. I prefer to think of a structure as a simple place to hold a small amount of data. If I need to manage a large amount of data (like, for a customer), or need nested data (Invoice + it's detail lines), then I'd use a class.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top