Choosing between classes and structures

Consider creating a structure when one or more of the following conditions apply:

  • The structure's primary purpose is to encapsulate a few relatively simple data values
  • It is reasonable to expect that the encapsulated values will be copied rather than referenced when you assign or pass around an instance of the structure
  • Any properties stored by the structure are themselves value types, which would also be expected to be copied rather than referenced
  • The structure does not need to inherit properties or behavior from another existing type

Examples of good candidates for structures include the following:

  • The size of a geometric shape
  • A point in a 3D coordinate system
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset