From the course: C# Essential Training 1: Types and Control Flow

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Defining constructors

Defining constructors

- [Instructor] With our types to find, we can start thinking about, how other developers or ourselves, are going to construct instances of these types. So we can start defining constructors for our classes. Go into my Employee class here, we use the little keyboard shortcut, typing ctor and Tab twice. Now I have a public Employee, then I'll just add two parameters here. String firstName, string lastName, and then inside of the constructor and set the properties. So LastName equals lastName, and FirstName equals firstName. And of course confirmation, that C-sharp is case sensitive. We've got a property name, it's different from our parameter name, simply by the first letter. And that now allows me to create an employee, passing in the firstName and lastName, and initializing the object with that state. I may have caught down here on line 28 though, that my Manager class, which derives from Employee is now giving me a red squiggly, which will turn into a compiler error, that says…

Contents