3 ms·
If you want to see how much code you get 'for free' by defining a record that you used to have to do manually, check out the generated C# here (structural equa
by Serow225 6y ago
If you want to see how much code you get 'for free' by defining a record that you used to have to do manually, check out the generated C# here
(structural equality, GetHashCode, Deconstruct, cloning for 'with', pretty printing, etc)
https://sharplab.io/#v2:EYLgtghgzgLgpgJwDQBMQGoA+BYAUANwgQAIAzAe3OIF5iA7OAd2IAVEpy6AKAIgClycHkmIAmAAwBKANx48COAGNyCFK3adiXAAIBGccQByEMHBEBLOjGIBBAOZwZc3AHoX5u3RVxiMABbmUMSMKgDWROQArnRqFCRQfkQADgA2EMDEYIFQlnbEAMIAxACcxFCRSUkqMHh0JnBQSRCKPnoAdABK0TDmpm355GBJ5imIAMqI+OYtQQDeeMSLxNoAzMuixACSUACiAB7wCHUpm3Tm1rMAvniXQA== https://sharplab.io/#v2:EYLgtghgzgLgpgJwDQBMQGoA+BYAUANwgQAI...
- Jordanpomeroy 6y agoThat’s neat! It’s also generating code for the main method, which is also a new c# 9 feature
- Renaud 6y agoAren't records meant to be immutable? I don't understand why properties have setters in the generated definition of the record. I'm missing something.
- Todd 6y agoConstructor-defined properties of records are implemented using auto-implemented properties with the new init keyword, so: public int MyProp { get; init; } instead of public int MyProp { get; set; } Apparently those are implemented using readonly backing fields while still retaining property setters.