<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Bhawesh Kafle on Medium]]></title>
        <description><![CDATA[Stories by Bhawesh Kafle on Medium]]></description>
        <link>https://medium.com/@developer.bhawesh?source=rss-5b76354f1203------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*PwwTYrTU43X0bi0p4Lwd7g.jpeg</url>
            <title>Stories by Bhawesh Kafle on Medium</title>
            <link>https://medium.com/@developer.bhawesh?source=rss-5b76354f1203------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 13:21:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@developer.bhawesh/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[ C# 14: Field-Backed Properties Make Auto-Properties Smarter]]></title>
            <link>https://medium.com/@developer.bhawesh/c-14-field-backed-properties-make-auto-properties-smarter-879c625878ba?source=rss-5b76354f1203------2</link>
            <guid isPermaLink="false">https://medium.com/p/879c625878ba</guid>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[new-feature-releases]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[whats-new]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <dc:creator><![CDATA[Bhawesh Kafle]]></dc:creator>
            <pubDate>Sun, 16 Nov 2025 01:51:30 GMT</pubDate>
            <atom:updated>2025-11-16T01:51:30.176Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YnV7jAv7LG0Rjj4fi66aPQ.png" /></figure><p>If you’ve worked with C#, you probably love auto-properties for their simplicity:</p><pre>public int Age { get; set; }</pre><p>They save time and keep code clean. But here’s the catch: what happens when you realize you need validation, logging, or transformation in your property?</p><p>Before C# 14, you had to rewrite it with a private backing field:</p><pre>private int _age;<br>public int Age<br>{<br>    get =&gt; _age;<br>    set<br>    {<br>        if (value &lt; 0) throw new ArgumentException(&quot;Age cannot be negative&quot;);<br>        _age = value;<br>    }<br>}</pre><p>It works, but it feels clunky and adds boilerplate code.</p><h3>C# 14 and the field keyword</h3><p>C# 14 introduces a simple but powerful feature: field-backed properties. With the field contextual keyword, you can access the compiler-generated backing field without declaring a separate variable.</p><pre>public int Age<br>{<br>    get =&gt; field;<br>    set<br>    {<br>        if (value &lt; 0)<br>            throw new ArgumentException(&quot;Age cannot be negative&quot;);<br>field = value;<br>    }<br>}</pre><p>✅ No extra private fields</p><p>✅ Cleaner, shorter, and readable code</p><p>✅ Easy to add logic anytime</p><h3>How it works</h3><ul><li>The compiler automatically creates a hidden backing field for your property.</li><li>Using the keyword field, you can get or set that backing field inside your property accessors.</li><li>You can now safely add validation, logging, trimming strings, or any custom logic without rewriting the property from scratch.</li></ul><p>Example:</p><pre>public string Name<br>{<br>    get =&gt; field;<br>    set =&gt; field = value?.Trim(); // automatically trims whitespace<br>}</pre><h3>Why this matters</h3><ol><li>Start simple, evolve later — Begin with a plain auto-property, add logic when needed.</li><li>Less boilerplate — Cleaner code, fewer mistakes.</li><li>Flexible and maintainable — Works for validation, logging, transformations… whatever your project needs.</li></ol><p>Hit Like, Share and Repost if you liked it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=879c625878ba" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>