Chapter 3Objects and Types

WHAT’S IN THIS CHAPTER?

  • The differences between classes and structs
  • Class members
  • Passing values by value and by reference
  • Method overloading
  • Constructors and static constructors
  • Read-only fields
  • Partial classes
  • Static classes
  • Weak references
  • The Object class, from which all other types are derived

WROX.COM CODE DOWNLOADS FOR THIS CHAPTER

The wrox.com code downloads for this chapter are found at www.wrox.com/go/procsharp on the Download Code tab. The code for this chapter is divided into the following major examples:

  • MathTest
  • MathTestWeakReference
  • ParameterTest

CREATING AND USING CLASSES

So far, you’ve been introduced to some of the building blocks of the C# language, including variables, data types, and program flow statements, and you have seen a few very short complete programs containing little more than the Main() method. What you haven’t seen yet is how to put all these elements together to form a longer, complete program. The key to this lies in working with classes — the subject of this chapter. Note that we cover inheritance and features related to inheritance in Chapter 4, “Inheritance.”

CLASSES AND STRUCTS

Classes and structs ...

Get Professional C# 5.0 and .NET 4.5.1 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.