O'Reilly logo

Professional C# 2012 and .NET 4.5 by Morgan Skinner, Karli Watson, Jay Glynn, Bill Evjen, Christian Nagel

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 3

Objects 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 http://www.wrox.com/remtitle.cgi?isbn=1118314425 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.”

NOTE This chapter introduces the basic syntax associated with classes. However, we assume that you are already familiar with the underlying principles of using classes — for example, that you know what a constructor or a property is. This chapter is largely confined to applying those principles in C# code.

CLASSES AND STRUCTS ...

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