O'Reilly logo

Beginning Microsoft® Visual C#® 2008 by Eric White, Morgan Skinner, Jon D. Reid, Jacob Hammer Pedersen, Christian Nagel, Karli Watson

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 10. Defining Class Members

This chapter continues exploring class definitions in C# by looking at how you define field, property, and method class members. You start by examining the code required for each of these types, and learn how to generate the structure of this code using wizards. You also learn how to modify members quickly by editing their properties.

After covering the basics of member definition, you'll learn some advanced techniques involving members: hiding base class members, calling overridden base class members, nested type definitions, and partial class definitions.

Finally, you put theory into practice by creating a class library that you can build on and use in later chapters.

In this chapter you learn how to do the following:

  • Work with fields, properties, and method class members.

  • Create a class library.

Member Definitions

Within a class definition, you provide definitions for all members of the class, including fields, methods, and properties. All members have their own accessibility levels, defined in all cases by one of the following keywords:

  • public—Members are accessible from any code.

  • private—Members are accessible only from code that is part of the class (the default if no keyword is used).

  • internal—Members are accessible only from code within the project (assembly) where they are defined.

  • protected—Members are accessible only from code that is part of either the class or a derived class.

The last two of these can be combined, so protected internal members ...

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