{"id":33279,"date":"2021-06-29T18:05:00","date_gmt":"2021-06-29T16:05:00","guid":{"rendered":"https:\/\/blexin.com\/?p=33279"},"modified":"2021-07-14T17:18:30","modified_gmt":"2021-07-14T15:18:30","slug":"custom-records-in-c-9","status":"publish","type":"post","link":"https:\/\/blexin.com\/en\/blog-en\/custom-records-in-c-9\/","title":{"rendered":"Custom records in C# 9"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"608\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2021\/06\/12_ITA_1105x656_blog-c9record-B.png?resize=1024%2C608&#038;ssl=1\" alt=\"\" class=\"wp-image-33259\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2021\/06\/12_ITA_1105x656_blog-c9record-B-1024x608.png 1024w, https:\/\/blexin.com\/wp-content\/uploads\/2021\/06\/12_ITA_1105x656_blog-c9record-B-980x582.png 980w, https:\/\/blexin.com\/wp-content\/uploads\/2021\/06\/12_ITA_1105x656_blog-c9record-B-480x285.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1024px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In the <a href=\"https:\/\/blexin.com\/en\/blog-en\/positional-records-c-9\/\" target=\"_blank\" rel=\"noreferrer noopener\">previous article<\/a>, we analyzed the <em>Positional Records <\/em>that are the real innovation of this new functionality of C# 9. We discovered that behind the scenes a <em>record <\/em>is nothing but a class with specific default behaviors, including the immutability and equality of values.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Would it therefore be possible to write a <em>record <\/em>with a syntax similar to that of a class? Yes, of course! Let&#8217;s see it:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n    public record CustomRecordPerson\n    {\n        public string Name { get; set; }\n        public string Surname { get; set; }\n\n        public CustomRecordPerson(string name, string surname)\n        {\n            Name = name;\n            Surname = surname;\n        }\n\n        public CustomRecordPerson()\n        {\n        }\n    }\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">As we can see, the only difference with the definition of a <em>class<\/em>, consists of using the <em>record <\/em>keyword instead of the keyword <em>class<\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We can therefore create an instance of our <em>record <\/em>through the constructor:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nvar customRecordPerson = new CustomRecordPerson(name: &quot;Francesco&quot;, surname:&quot;Vas&quot;); \n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Or through an <em>object initializer<\/em>, which, I remind you, we can use it only if we also have a constructor without parameters:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nvar customRecordPerson2 = new CustomRecordPerson \n{ \n    Name = &quot;Francesco&quot;, \n    Surname = &quot;Vas&quot; \n}; \n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Now let&#8217;s try to modify one of our <em>record<\/em>\u2019s the properties:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\ncustomRecordPerson.Name = &quot;Adolfo&quot;; \n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">We know that the properties of a <em>record<\/em> are immutable and for someone could therefore be a surprise that the compiler does not signal an error. Despite this supposition, we can change the value of a property without problems!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We must not mistakenly think that a <em>record <\/em>is an always immutable data structure. Properties passed as an argument in the case of <a href=\"https:\/\/blexin.com\/en\/blog-en\/positional-records-c-9\/\" target=\"_blank\" rel=\"noreferrer noopener\">positional records <\/a>are always immutable.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As we have seen, these are set by default as init-only properties. We can do the same in our case to get the immutability:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\npublic record CustomRecordPerson  \n{ \n    public string Name { get; init; } \n    public string Surname { get; init; } \n\n    \/\/... \n} \n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Instead of the classic setter type accessor method, we need to use the <em>init-only setter <\/em>type <em>accessor<\/em> method for properties that we want to make immutable.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We have already talked about the keyword <em>init<\/em>, and we know that it allows us to specify that the value of that property can only be set when the object is initialized but cannot be changed later.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We will deepen even more by saying that this new feature allows us to obtain a <em>read-only backing-field <\/em>for the property, which the compiler generates for us behind the scenes:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n&#x5B;CompilerGenerated] \n&#x5B;DebuggerBrowsable(DebuggerBrowsableState.Never)] \nprivate readonly string &lt;Name&gt;k__BackingField; \n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">So basically, using&nbsp;the&nbsp;<em>init&nbsp;<\/em>keyword for a property of a&nbsp;<em>class&nbsp;<\/em>or a&nbsp;<em>record&nbsp;<\/em>is&nbsp;the same as writing:&nbsp;<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\npublic class Person \n{ \n    private readonly string _name; \n\n    public Person(string name) \n    { \n        Name = name; \n    } \n\n    public string Name \n    { \n        get =&gt; _name; \n        init =&gt; _name = value; \n    } \n} \n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">If we try to replace the&nbsp;<em>init&nbsp;<\/em>keyword with the keyword&nbsp;<em>set<\/em>, the compiler would signal us an error:&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"214\" data-attachment-id=\"33270\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/custom-records-in-c-9\/attachment\/1-set-error-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2021\/06\/1-set-error.png?fit=1024%2C214&amp;ssl=1\" data-orig-size=\"1024,214\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"1-set-error\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2021\/06\/1-set-error.png?fit=1024%2C214&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2021\/06\/1-set-error.png?resize=1024%2C214&#038;ssl=1\" alt=\"\" class=\"wp-image-33270\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2021\/06\/1-set-error.png 1024w, https:\/\/blexin.com\/wp-content\/uploads\/2021\/06\/1-set-error-980x205.png 980w, https:\/\/blexin.com\/wp-content\/uploads\/2021\/06\/1-set-error-480x100.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1024px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">It happens because the <em>init-only<\/em> type accessor methods are enabled to modify read-only fields.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here are all the secrets behind the immutability introduced in C # 9!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Regardless of the use of the immutability and therefore of the <em>init<\/em> keyword, obviously also a record written with this alternative syntax provides us with some of the features we have already seen for <em>positional records<\/em>. Let us then consider the following definition of a <em>record<\/em>, in which we specified only two properties<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\npublic record CustomRecordPerson  \n{ \n    public string Name { get; init; } \n    public string Surname { get; init; } \n} \n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">And let&#8217;s analyze the generated IL code:&nbsp;<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\npublic class CustomRecordPerson : IEquatable&lt;CustomRecordPerson&gt; \n{ \n    protected virtual Type EqualityContract \n    { \n        &#x5B;System.Runtime.CompilerServices.NullableContext(1)] \n        &#x5B;CompilerGenerated] \n        get \n        { \n            return typeof(CustomRecordPerson); \n        } \n    } \n \n    public string Name { get; init; } \n \n    public string Surname { get; init; } \n \n    public override string ToString() \n    { \n        StringBuilder stringBuilder = new StringBuilder(); \n        stringBuilder.Append(&quot;CustomRecordPerson&quot;); \n        stringBuilder.Append(&quot; { &quot;); \n        if (PrintMembers(stringBuilder)) \n        { \n            stringBuilder.Append(&quot; &quot;); \n        } \n        stringBuilder.Append(&quot;}&quot;); \n        return stringBuilder.ToString(); \n    } \n \n    protected virtual bool PrintMembers(StringBuilder builder) \n    { \n        builder.Append(&quot;Name&quot;); \n        builder.Append(&quot; = &quot;); \n        builder.Append((object?)Name); \n        builder.Append(&quot;, &quot;); \n        builder.Append(&quot;Surname&quot;); \n        builder.Append(&quot; = &quot;); \n        builder.Append((object?)Surname); \n        return true; \n    } \n \n    &#x5B;System.Runtime.CompilerServices.NullableContext(2)] \n    public static bool operator !=(CustomRecordPerson? r1, CustomRecordPerson? r2) \n    { \n        return !(r1 == r2); \n    } \n \n    &#x5B;System.Runtime.CompilerServices.NullableContext(2)] \n    public static bool operator ==(CustomRecordPerson? r1, CustomRecordPerson? r2) \n    { \n        return (object)r1 == r2 || (r1?.Equals(r2) ?? false); \n    } \n \n    public override int GetHashCode() \n    { \n        return (EqualityComparer&lt;Type&gt;.Default.GetHashCode(EqualityContract) * -1521134295 + \n        EqualityComparer&lt;string&gt;.Default.GetHashCode(Name)) * -1521134295 + \n        EqualityComparer&lt;string&gt;.Default.GetHashCode(Surname); \n    } \n \n    public override bool Equals(object? obj) \n    { \n        return Equals(obj as CustomRecordPerson); \n    } \n \n    public virtual bool Equals(CustomRecordPerson? other) \n    { \n         return (object)other != null &amp;&amp; EqualityContract == other!.EqualityContract &amp;&amp;  \n         EqualityComparer&lt;string&gt;.Default.Equals(Name, other!.Name) &amp;&amp; \n         EqualityComparer&lt;string&gt;.Default.Equals(Surname, other!.Surname); \n     } \n \n    public virtual CustomRecordPerson &lt;Clone&gt;$() \n    { \n        return new CustomRecordPerson(this); \n    } \n \n    protected CustomRecordPerson(CustomRecordPerson original) \n    { \n        Name = original.Name; \n        Surname = original.Surname; \n    } \n \n    public CustomRecordPerson() \n    { \n    } \n} \n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">We will not dwell on analyzing all the features, which we have already discussed in the previous article on <a href=\"https:\/\/blexin.com\/en\/blog-en\/positional-records-c-9\/\" target=\"_blank\" rel=\"noreferrer noopener\">positional records<\/a>. We will only analyze the differences between the features offered automatically by the two different ways of writing a <em>record<\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As we see in this case, we do not automatically obtain the <em>parameterized constructor<\/em>, and therefore just as for a normal <em>class<\/em>, we have been provided by the <em>default constructor<\/em>. We still have all the methods and overrides supporting <em>structural equality <\/em>and the ToString() method override, which provides us text representation of the type and values of the properties of the <em>record<\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But the <strong>deconstructor<\/strong> lacks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For both syntaxes, there are a <em>protected constructor <\/em>and a <em>virtual method Clone(), <\/em>which we have not treated previously. Still, the behavior of non-destructive mutation implemented by <em>record<\/em> is based on them, that is the operation of the with keyword.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Regardless of the syntax used, <em>records<\/em> support inheritance. In fact, a record can inherit from another <em>record<\/em> and can also be <em>abstract type<\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But a record cannot inherit from a <em>class<\/em>, and a class cannot inherit from a <em>record<\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We can also use generic <em>constraints<\/em>, and even if there is no generic constraint for the records, the records satisfy the class constraint. This means that we could use, for example, <em>generic constraints <\/em>in these ways:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\npublic record GenericRecord&lt;T&gt; where T : class \n{ \n} \npublic class GenericClass&lt;T&gt; where T : CustomRecordPerson \n{ \n} \n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">We finish here the deepening on the records.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We have already talked about the possible fields of use of the records. We have learned that they are nothing but classes with specific default behaviors and that there are two types of syntax to write them that provide us more or less the same functionalities.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Honestly, without particular needs in terms of customization, I believe that the syntax of <a href=\"https:\/\/blexin.com\/en\/blog-en\/positional-records-c-9\/\" target=\"_blank\" rel=\"noreferrer noopener\">positional records<\/a> is much more useful because it allows us an obvious savings of quantity of written code and, therefore, development time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When is it better to use a record instead of a class?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Mostly, if we want to define a model that depends on the equality of values and if we want to determine a reference type for which objects are not editable.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I hope you found the topic interesting, see you in the next article!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Stay Tuned!<\/p>\n\n\n\n\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s continue our investigation to discover Records in C # 9 <\/p>\n","protected":false},"author":196716244,"featured_media":33260,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"off","_et_pb_old_content":"","_et_gb_content_width":"","_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","_crdt_document":"","inline_featured_image":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_wpas_customize_per_network":false,"jetpack_post_was_ever_published":false},"categories":[688637524],"tags":[688637384],"class_list":["post-33279","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-en","tag-c-en"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Custom records in C# 9 - Blexin<\/title>\n<meta name=\"description\" content=\"Records never stop surprising us: the most important news of C# 9 can also be written with a syntax similar to that of a class.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blexin.com\/en\/blog-en\/custom-records-in-c-9\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Custom records in C# 9 - Blexin\" \/>\n<meta property=\"og:description\" content=\"Records never stop surprising us: the most important news of C# 9 can also be written with a syntax similar to that of a class.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blexin.com\/en\/blog-en\/custom-records-in-c-9\/\" \/>\n<meta property=\"og:site_name\" content=\"Blexin\" \/>\n<meta property=\"article:published_time\" content=\"2021-06-29T16:05:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-07-14T15:18:30+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i1.wp.com\/blexin.com\/wp-content\/uploads\/2021\/06\/12_ITA_1105x656_blog-c9record-B.png?fit=1105%2C656&ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"1105\" \/>\n\t<meta property=\"og:image:height\" content=\"656\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Francesco Vastarella\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Francesco Vastarella\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/custom-records-in-c-9\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/custom-records-in-c-9\\\/\"},\"author\":{\"name\":\"Francesco Vastarella\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#\\\/schema\\\/person\\\/388dae0ca9df603c88b5e41e29cf2d4d\"},\"headline\":\"Custom records in C# 9\",\"datePublished\":\"2021-06-29T16:05:00+00:00\",\"dateModified\":\"2021-07-14T15:18:30+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/custom-records-in-c-9\\\/\"},\"wordCount\":836,\"image\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/custom-records-in-c-9\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2021\\\/06\\\/12_ITA_1105x656_blog-c9record-B.png?fit=1105%2C656&ssl=1\",\"keywords\":[\"C#\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/custom-records-in-c-9\\\/\",\"url\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/custom-records-in-c-9\\\/\",\"name\":\"Custom records in C# 9 - Blexin\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/custom-records-in-c-9\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/custom-records-in-c-9\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2021\\\/06\\\/12_ITA_1105x656_blog-c9record-B.png?fit=1105%2C656&ssl=1\",\"datePublished\":\"2021-06-29T16:05:00+00:00\",\"dateModified\":\"2021-07-14T15:18:30+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#\\\/schema\\\/person\\\/388dae0ca9df603c88b5e41e29cf2d4d\"},\"description\":\"Records never stop surprising us: the most important news of C# 9 can also be written with a syntax similar to that of a class.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/custom-records-in-c-9\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/custom-records-in-c-9\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/custom-records-in-c-9\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2021\\\/06\\\/12_ITA_1105x656_blog-c9record-B.png?fit=1105%2C656&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2021\\\/06\\\/12_ITA_1105x656_blog-c9record-B.png?fit=1105%2C656&ssl=1\",\"width\":1105,\"height\":656,\"caption\":\"custom record in csharp 9\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/custom-records-in-c-9\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/blexin.com\\\/en\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Custom records in C# 9\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#website\",\"url\":\"https:\\\/\\\/blexin.com\\\/en\\\/\",\"name\":\"Blexin\",\"description\":\"Con noi \u00e8 semplice\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/blexin.com\\\/en\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#\\\/schema\\\/person\\\/388dae0ca9df603c88b5e41e29cf2d4d\",\"name\":\"Francesco Vastarella\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3b8deedae8f35372d5fba49f918006fb0a58a2943aff6ae52d3ff188e0c441bb?s=96&d=identicon&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3b8deedae8f35372d5fba49f918006fb0a58a2943aff6ae52d3ff188e0c441bb?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3b8deedae8f35372d5fba49f918006fb0a58a2943aff6ae52d3ff188e0c441bb?s=96&d=identicon&r=g\",\"caption\":\"Francesco Vastarella\"},\"url\":\"https:\\\/\\\/blexin.com\\\/en\\\/author\\\/francesco-vastarellablexin-com\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Custom records in C# 9 - Blexin","description":"Records never stop surprising us: the most important news of C# 9 can also be written with a syntax similar to that of a class.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blexin.com\/en\/blog-en\/custom-records-in-c-9\/","og_locale":"en_US","og_type":"article","og_title":"Custom records in C# 9 - Blexin","og_description":"Records never stop surprising us: the most important news of C# 9 can also be written with a syntax similar to that of a class.","og_url":"https:\/\/blexin.com\/en\/blog-en\/custom-records-in-c-9\/","og_site_name":"Blexin","article_published_time":"2021-06-29T16:05:00+00:00","article_modified_time":"2021-07-14T15:18:30+00:00","og_image":[{"width":1105,"height":656,"url":"https:\/\/i1.wp.com\/blexin.com\/wp-content\/uploads\/2021\/06\/12_ITA_1105x656_blog-c9record-B.png?fit=1105%2C656&ssl=1","type":"image\/png"}],"author":"Francesco Vastarella","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Francesco Vastarella","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blexin.com\/en\/blog-en\/custom-records-in-c-9\/#article","isPartOf":{"@id":"https:\/\/blexin.com\/en\/blog-en\/custom-records-in-c-9\/"},"author":{"name":"Francesco Vastarella","@id":"https:\/\/blexin.com\/en\/#\/schema\/person\/388dae0ca9df603c88b5e41e29cf2d4d"},"headline":"Custom records in C# 9","datePublished":"2021-06-29T16:05:00+00:00","dateModified":"2021-07-14T15:18:30+00:00","mainEntityOfPage":{"@id":"https:\/\/blexin.com\/en\/blog-en\/custom-records-in-c-9\/"},"wordCount":836,"image":{"@id":"https:\/\/blexin.com\/en\/blog-en\/custom-records-in-c-9\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2021\/06\/12_ITA_1105x656_blog-c9record-B.png?fit=1105%2C656&ssl=1","keywords":["C#"],"articleSection":["Blog"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/blexin.com\/en\/blog-en\/custom-records-in-c-9\/","url":"https:\/\/blexin.com\/en\/blog-en\/custom-records-in-c-9\/","name":"Custom records in C# 9 - Blexin","isPartOf":{"@id":"https:\/\/blexin.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/blexin.com\/en\/blog-en\/custom-records-in-c-9\/#primaryimage"},"image":{"@id":"https:\/\/blexin.com\/en\/blog-en\/custom-records-in-c-9\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2021\/06\/12_ITA_1105x656_blog-c9record-B.png?fit=1105%2C656&ssl=1","datePublished":"2021-06-29T16:05:00+00:00","dateModified":"2021-07-14T15:18:30+00:00","author":{"@id":"https:\/\/blexin.com\/en\/#\/schema\/person\/388dae0ca9df603c88b5e41e29cf2d4d"},"description":"Records never stop surprising us: the most important news of C# 9 can also be written with a syntax similar to that of a class.","breadcrumb":{"@id":"https:\/\/blexin.com\/en\/blog-en\/custom-records-in-c-9\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blexin.com\/en\/blog-en\/custom-records-in-c-9\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blexin.com\/en\/blog-en\/custom-records-in-c-9\/#primaryimage","url":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2021\/06\/12_ITA_1105x656_blog-c9record-B.png?fit=1105%2C656&ssl=1","contentUrl":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2021\/06\/12_ITA_1105x656_blog-c9record-B.png?fit=1105%2C656&ssl=1","width":1105,"height":656,"caption":"custom record in csharp 9"},{"@type":"BreadcrumbList","@id":"https:\/\/blexin.com\/en\/blog-en\/custom-records-in-c-9\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blexin.com\/en\/"},{"@type":"ListItem","position":2,"name":"Custom records in C# 9"}]},{"@type":"WebSite","@id":"https:\/\/blexin.com\/en\/#website","url":"https:\/\/blexin.com\/en\/","name":"Blexin","description":"Con noi \u00e8 semplice","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blexin.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blexin.com\/en\/#\/schema\/person\/388dae0ca9df603c88b5e41e29cf2d4d","name":"Francesco Vastarella","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3b8deedae8f35372d5fba49f918006fb0a58a2943aff6ae52d3ff188e0c441bb?s=96&d=identicon&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/3b8deedae8f35372d5fba49f918006fb0a58a2943aff6ae52d3ff188e0c441bb?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3b8deedae8f35372d5fba49f918006fb0a58a2943aff6ae52d3ff188e0c441bb?s=96&d=identicon&r=g","caption":"Francesco Vastarella"},"url":"https:\/\/blexin.com\/en\/author\/francesco-vastarellablexin-com\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2021\/06\/12_ITA_1105x656_blog-c9record-B.png?fit=1105%2C656&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pcyUBx-8EL","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts\/33279","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/users\/196716244"}],"replies":[{"embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/comments?post=33279"}],"version-history":[{"count":9,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts\/33279\/revisions"}],"predecessor-version":[{"id":33328,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts\/33279\/revisions\/33328"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/media\/33260"}],"wp:attachment":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/media?parent=33279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/categories?post=33279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/tags?post=33279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}