Implement class properties and methods

Beginner
Developer
Higher Education Educator
K-12 Educator
Student
Visual Studio Code

Learn how to implement read-write, read-only, and write-only class properties using property accessors and access modifiers, and how to implement methods and extension methods for a class.

Learning objectives

After completing this module, you'll be able to:

  • Explain how the field, property, and method members of a class are used in the class definition and instantiated objects.

  • Implement class properties using 'get' and 'set' property accessors.

  • Create classes that use automatically implemented properties.

  • Create read-only and write-only properties using access modifiers for properties and property accessors.

  • Create class methods and overloaded methods that accept zero or more arguments using either 'value' or 'reference' types.

  • Create extension methods for a class.

  • Implement classes that use a combination of properties and methods to manage encapsulated data.

Prerequisites

  • The ability to create classes and class constructors to instantiate objects in a C# app.

  • The ability to develop C# console apps that implement business logic using iteration statements, selection statements, and custom methods.

  • The ability to perform basic C# code debugging and exception handling in a Visual Studio Code environment.