From the course: Advanced C#: Object-Oriented Programming

Unlock the full course today

Join today to access over 24,500 courses taught by industry experts.

Solution: Add static members to employee

Solution: Add static members to employee - C# Tutorial

From the course: Advanced C#: Object-Oriented Programming

Solution: Add static members to employee

(upbeat music) - [Instructor] For this challenge, we needed to update our employee class with some static members to keep track of the number of employees created, as well as assigning IDs to each employee automatically. So let's take a look at my solution. I created two member variables for my class. The first is a private member that counts the number of objects, and the second is a protected member that increments each time an ID is needed. I made the first one private so that only my Employee class could access it. The second one is protected, just in case a subclass needs to see what the current ID counter is, and that's in the future if this program ever gets extended and so on. To go along with my private empCount variable, I define a public facing, where is it? Here it is. I define a public facing employee count static property. Note that it only has a get accessor, which prevents the property from being…

Contents