From the course: Learning C#
Unlock the full course today
Join today to access over 24,300 courses taught by industry experts.
Defining properties - C# Tutorial
From the course: Learning C#
Defining properties
- [Instructor] Now that we've learned how to control and define access to the number of variables and methods within our class definition using access modifiers, we're going to take a look at how we can safely expose them to other parts of our application. Now, in a previous example, we saw how to do this using public methods but it's a bit cumbersome to define methods just for accessing data fields. Methods should be doing real work instead of just setting and getting values. So instead, we're going to expose our object's data using properties, which are sort of a combination of member variables and methods. So let's take a look at an example. So here in our Classes folder, I'm going to open up the Properties folder and open up the Program file, as well as our Book class. So here we have the Book class example that we've been working with and it has three private data members. Name, author and pagecount. Now…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.