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.

Property pattern

Property pattern

- Another very useful pattern we can use is a property pattern. I'm going to create a method here. Its going to be a static bool. And we're going to check, "is weekend night shift". We're going to see for a given date and time, is this on a weekend? Friday or Saturday. And does it happen after 3:00 PM? So we're going to pass in the date time, called the shift date and we'll use our expression bodied method here. And I'm going to pass in that shift date to a switch expression. So we'll come down here, close that out. So we've got a method, we've got our switch expression on the shift date. And what I want to do is look at the properties of that date. So notice if I do curly braces here, I get all of the different properties of a date time. So now I could do our hour:, I could say, greater than or equal to 15, so 3:00 PM. And then I do a comma and now I have access to the properties again. So I could say day of week:, and then I can use the day of week, Monday, Friday, or day of week…

Contents