O'Reilly logo

C# 5.0 Programmer's Reference by Rod Stephens

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 12 Classes and Structures

What’s in This Chapter

  • Defining classes and structures
  • Value and reference types
  • Memory requirements, and heap and stack performance
  • Boxing and unboxing
  • Constructors and destructors
  • Garbage collection and Dispose

Wrox.com Downloads for This Chapter

Please note that all the code examples for this chapter are available as a part of this chapter’s code download on the book’s website at www.wrox.com/go/csharp5programmersref on the Download Code tab.

A variable holds a single value. It may be a simple value, such as an int or string, or a reference to a more complex entity such as a class or structure.

Classes and structures are both container types. They group related data values and methods into a convenient package that you can manipulate as a group.

For example, a Recipe class would contain fields or properties holding information about a recipe such as ingredients, temperature, instructions, and number of servings. It could also include methods to convert measurements between English and metric, to scale the recipe for different numbers of servings, and to print the recipe.

If you make an instance of the Recipe class and fill it with the data for a particular recipe, you can move the object around as a single unit instead of passing around separate variables holding the ingredients, temperature, instructions, and number of servings. The object also contains methods for manipulating the recipe, so you don’t need to write a separate module ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required