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.

Object initialization

Object initialization

- [Instructor] Well, you may quickly find, if you're not already familiar with it from your programming experience, is that defining constructors that meet everyone's need can be kind of challenging. You add the parameters you think people will use, but it's not exactly what they want. Rather than creating 10 or 15 different constructor options we can use these default parameters and really if we're going to do this correctly we should probably make this the employee ID property on our employee instead of the ID and we'll just fix that while we're here. But we've got all these other properties, so we've got age, we've got the employee ID, start date, shift start time, all these different pieces. So one of the things we can use in C# is called the object initialization. So rather than do the employee this way, I can come in and I can use curly braces rather than parentheses and now I can put the property name in. So I can say first name equals Matt, last name equals Milner. And I can…

Contents