Chapter 3. Objects and Types

So far, you've been introduced to some of the main building blocks that make up the C# language, including declaring variables, data types, and program flow statements, and you have seen a couple of very short complete programs containing little more than the Main() method. What you haven't really seen is how you can put all these together to form a longer, complete program. The key to this lies in working with classes—the subject of this chapter. In particular, this chapter covers:

  • The differences between classes and structs

  • Fields, properties, and methods

  • Passing values by value and reference

  • Method overloading

  • Constructors and static constructors

  • Read-only fields

  • The Object class, from which all other types are derived

Inheritance and features related to inheritance are discussed 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, and this chapter is largely confined to applying those principles in C# code. If you are not familiar with the concept of the class, you might want to take a look at Appendix A, which is available with the code downloads for the book on the Web at www.wrox.com.

This chapter introduces and explains those concepts that are not necessarily supported by most object-oriented languages. For example, although object constructors are ...

Get Professional C# 2005 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.