A structure is a bunch of variables stuck together with duct tape. If you want a bunch of independent-but-related variables stuck together with duct tape, it is often better to use a struct that exposes a bunch of variables stuck together with duct tape than to design a class which tries to serve that purpose, or a struct which pretends to be an object of a class which tries to serve that purpose. If, however, you want something that behaves as an object, then you should use a class.
Given card
defined as shown, card[] foo = new card[10]
will make foo
identify an array holding ten references of type PictureBox
and ten double
values. The declaration card bar;
will define space for another PictureBox
reference and another double
which are independent of anything else in the universe. Saying bar = foo[3];
will be equivalent to bar.picture = foo[3].picture; bar.value = foo[3].value;
, and will not establish any lasting relationship between the fields of bar
and those of foo[3]
.
Duct-taped-variable structures can be very useful for some purposes, such as holding the coordinates of a point, but it is important to recognize them for what they are. If you want a type to represent an object, use a class. Only if you want it to hold a bunch of independent but related variables duct-taped together should you use a struct
.