Hi Konrad,

thank you for spotting this error. I've corrected it. You were right, it must be State.Premium!

The example is not about which value the variable will have, it is a shell to demonstrate the property pattern.

Take this example from the official C# Website about new features of C#8.0

public static decimal ComputeSalesTax(Address location, decimal salePrice) =>

location switch

{

{ State: "WA" } => salePrice * 0.06M,

{ State: "MN" } => salePrice * 0.075M,

{ State: "MI" } => salePrice * 0.05M,

// other cases removed for brevity...

_ => 0M

};

You can easily switch out the properties values depending on another properties value.

Write that in your suggested syntax and see the difference immediately. Or compare X10 and X12 again. (Some other comments mentioned it is syntactic sugar, and this is true, but as Martin Fowler said "Any fool can write code that a computer can understand. Good programmers write code that humans can understand". IMHO, if I compare X10 with X12, I am more into X12 in point of readability and understanding.)

Furthermore you can outsource logic, that kind of belongs to the type/object you want to examine, but is not part of the core competence of that type/object.

source: https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8#property-patterns

I hope that helps you to understand the advantages of the property pattern :)

Feel free to contact me on Instagram: Arnold.code

Adventures instead of dull coding tutorials in Full Stack Web and C# Development. Diploma Engineer & Udemy Instructor: https://bit.ly/32qGFP1

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store