<?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 Sidharth CP on Medium]]></title>
        <description><![CDATA[Stories by Sidharth CP on Medium]]></description>
        <link>https://medium.com/@sidharth.cp34?source=rss-fbe6877b9ed0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Hxnjbx80P0VRQV5d</url>
            <title>Stories by Sidharth CP on Medium</title>
            <link>https://medium.com/@sidharth.cp34?source=rss-fbe6877b9ed0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 14:23:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sidharth.cp34/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[Upgrading a Locked-Down Linux Fleet with Nothing but kubectl]]></title>
            <link>https://medium.com/@sidharth.cp34/upgrading-a-locked-down-linux-fleet-with-nothing-but-kubectl-7e75a737e1f2?source=rss-fbe6877b9ed0------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e75a737e1f2</guid>
            <dc:creator><![CDATA[Sidharth CP]]></dc:creator>
            <pubDate>Mon, 14 Sep 2026 18:53:05 GMT</pubDate>
            <atom:updated>2026-09-14T18:53:05.433Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*GhDR7hH8MAwSeVe6KNn8EQ.png" /></figure><p>Say you’re running a fleet of machines on an <em>immutable</em> operating system — root filesystem read-only, nothing drifts, and you upgrade the whole OS as a single artifact instead of patching it in place. Great for reliability.</p><p>But now you need to do something mundane: rotate a login password across every node, or roll out a new OS version.</p><p>The obvious move is to SSH into each box and do it by hand. Except that’s exactly the kind of ad-hoc, drift-inducing change the immutable model exists to prevent — and on a real fleet, “SSH into each box” doesn’t scale past your patience.</p><p>So here’s the setup I landed on, and the thing I actually want to show you: <strong>I can change a password or push a full OS upgrade to the whole fleet by applying a single Kubernetes ConfigMap. No SSH, no per-node scripts, no drift.</strong></p><pre># Rotate the password everywhere:<br>kubectl get configmap kairos-config -n kube-system -o yaml | \<br>  sed &#39;s/passwd: kairos/passwd: something-better/&#39; | \<br>  kubectl apply -f -</pre><pre># Roll out a new OS image to the whole fleet:<br>kubectl create configmap kairos-upgrade \<br>  --from-literal=image=docker.io/you/kairos-rhel96:v2 \<br>  --from-literal=version=v2.0.0 \<br>  -n kube-system --dry-run=client -o yaml | kubectl apply -f -</pre><p>That’s the entire operator experience. Below is how it works — and, more interestingly, how I made it do that <em>without</em> handing a compromised container the keys to every machine.</p><h3>The one-paragraph background</h3><p>The OS here is <a href="https://kairos.io/">Kairos</a>, an open-source immutable Linux distribution built for running Kubernetes at the edge. The mental model: you build the OS like a container image, ship it as an artifact, and <em>replace</em> it wholesale to upgrade.</p><p>Upgrades write the new image to an inactive A/B partition and flip the bootloader to it — so a bad upgrade rolls back instead of leaving you with a half-patched box. My image is built on RHEL 9.6 with k3s baked in.</p><p>If you’ve never touched Kairos, that’s all you need to follow along. The interesting part isn’t Kairos itself.</p><h3>The interesting part: how a kubectl apply becomes a change on the host</h3><p>The gap I had to bridge is this: editing a ConfigMap happens <em>inside</em> Kubernetes, but flipping a GRUB partition, running an OS upgrade, or rebooting a node happens <em>on the host</em>, as root, outside the cluster’s world. Something has to cross that boundary.</p><p>The naive way to cross it is a <strong>privileged DaemonSet</strong> — a pod with the host’s PID namespace, the host root filesystem mounted in, and all Linux capabilities intact. It works, and it’s a trap.</p><p>A pod with that much power is one of the cleanest paths on a whole cluster from “attacker gets into a container” to “attacker has root on every node.” A bad base image, one poisoned dependency, a sloppy RBAC rule — any of those, and a privileged DaemonSet hands the whole fleet over.</p><p>So I split the job in two, along the privilege boundary:</p><ul><li><strong>In the cluster:</strong> an <em>unprivileged</em> DaemonSet pod. All capabilities dropped, allowPrivilegeEscalation: false, and its only reach into the host is two narrow hostPath mounts — /oem and /usr/local. It can <em>write two files</em>. That&#39;s the entire blast radius. It reads the ConfigMaps you apply and drops the requested change into those files.</li><li><strong>On the host:</strong> a plain root-owned systemd service (kairos-agent-watcher) that loops every 15 seconds, reads only those same two files, and does the actual privileged work — applying config with kairos-agent run-stage, flipping the A/B slot, running an upgrade, rebooting.</li></ul><p>The payoff is the security property: the pod that faces the cluster has almost no power, and the process that has all the power never faces the cluster.</p><p>If someone fully owns the DaemonSet pod, the worst they can do is write a config change or point at an upgrade image. They still can’t run an arbitrary command as root on the node, because nothing in the pod ever <em>executes</em> privileged work — the privilege lives in a service that only ever reads two files.</p><p>That’s the idea I’d take to any host-level-ops-from-Kubernetes problem, Kairos or not: don’t grant the network-facing thing the privilege; let it express <em>intent</em> into a narrow channel, and keep the privilege on the other side of that channel.</p><p>The flow, end to end:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*rc1k0jd6hmIxqP2CknglBg.png" /></figure><h3>A scar worth sharing: the disk that installed itself across two disks</h3><p>One more piece runs earlier, at install time — a small service that picks <em>which disk</em> the OS lands on. On a multi-disk box you don’t want the OS installing over your data disk or your install media, so the script picks the smallest attached disk over 20GB that isn’t the boot media.</p><p>That sounds simple. It was not simple, and I want to be honest about how I learned that, because it’s the kind of thing you won’t find in the docs.</p><p>The one that actually hurt showed up <em>after</em> we shipped it to a client. On their hardware, the install would sometimes end up with the OS partitions <strong>split across two different disks</strong> — some on one, some on another.</p><p>It took a bunch of back-and-forth with my team to work out why: those disks had been used for a previous Kairos install, and the leftover Kairos partition labels (COS_GRUB, COS_OEM, COS_STATE, and friends) were still on them.</p><p>Kairos finds its partitions <em>by label</em>. With stale labels lying around on a second disk, the installer happily adopted them, and the install smeared itself across both.</p><p>The fix is unglamorous and now lives in the script: before install, scrub any stale Kairos labels off the candidate disks (wipefs, sgdisk --zap-all) so nothing gets adopted by accident.</p><p>But the lesson is the transferable bit: <em>label-based partition discovery trusts labels, so an install onto previously-used hardware has to assume those labels are lying.</em> That’s a sentence I wish I’d read before shipping, not after.</p><p>(That scrub step is destructive by design — it’s meant for lab and disposable-disk hardware. Read it before you point it at anything you care about.)</p><h3>The whole thing is on GitHub</h3><p>The full working setup — the Dockerfile, both systemd services, the DaemonSet and ConfigMaps, the disk-select script, and step-by-step commands to build the image, produce an ISO, spin up a demo VM, and test both a password rotation and a live OS upgrade end to end — is here:</p><p><strong>→ </strong><a href="https://github.com/sidharth48-hub/kairos"><strong>https://github.com/sidharth48-hub/kairos</strong></a></p><p>The README walks through it in order and calls out what’s demo-only (default passwords, the destructive disk scrub) versus what’s safe to reuse.</p><p>If you’re running immutable Linux under Kubernetes and you’ve been SSHing into nodes for day-2 changes, I think the pod-writes-intent / host-holds-privilege split is worth stealing — even if you never touch Kairos.</p><p>Happy to answer questions in the comments — especially if you’ve solved the host-ops-from-a-cluster problem a different way. I’d like to hear it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e75a737e1f2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OpenAPI & Swagger Enhancements in ASP.NET Core 10: The Complete 2025 Guide]]></title>
            <link>https://medium.com/@sidharth.cp34/openapi-swagger-enhancements-in-asp-net-core-10-the-complete-2025-guide-2fa6da93a7fb?source=rss-fbe6877b9ed0------2</link>
            <guid isPermaLink="false">https://medium.com/p/2fa6da93a7fb</guid>
            <dc:creator><![CDATA[Sidharth CP]]></dc:creator>
            <pubDate>Sun, 19 Oct 2025 16:17:03 GMT</pubDate>
            <atom:updated>2025-10-19T16:17:03.722Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zrJJzMsLKVMlJY1kMRl_dw.png" /></figure><h3>Introduction</h3><p>If you’ve built APIs with ASP.NET Core, chances are you’ve relied on <strong>Swagger</strong> and <strong>OpenAPI</strong> for documentation and testing.</p><p>In 2025, with the release of <strong>.NET 10 and ASP.NET Core 10</strong>, Microsoft has introduced a series of <strong>enhancements to OpenAPI integration</strong>, making it easier than ever to document, version, and test APIs — especially with <strong>Minimal APIs</strong> and <strong>Native AOT</strong> apps.</p><p>This article walks through the latest improvements, how to enable them, and how to take your API documentation to the next level.</p><h3>What’s New in ASP.NET Core 10 OpenAPI Support?</h3><h4>1️⃣ <strong>Built-in OpenAPI Support for Minimal APIs</strong></h4><p>In .NET 10, Minimal APIs now come with <strong>first-class OpenAPI support</strong> — no more heavy dependencies or workarounds.</p><p>You can now generate full OpenAPI documentation for your Minimal API endpoints with a few simple lines of code.</p><pre>var builder = WebApplication.CreateBuilder(args);<br>builder.Services.AddEndpointsApiExplorer();<br>builder.Services.AddSwaggerGen();<br><br>var app = builder.Build();<br><br>app.MapGet(&quot;/weather&quot;, () =&gt;<br>{<br>    return new { Temperature = &quot;25°C&quot;, Condition = &quot;Sunny&quot; };<br>})<br>.WithName(&quot;GetWeather&quot;)<br>.WithOpenApi();<br><br>app.UseSwagger();<br>app.UseSwaggerUI();<br><br>app.Run();</pre><p><strong>Notice the </strong><strong>.WithOpenApi() extension</strong> — this automatically infers schema and metadata for your endpoint.</p><h4>2️⃣ <strong>Better Schema Generation</strong></h4><p>The new OpenAPI generator in ASP.NET Core 10 produces <strong>cleaner, more compliant schemas</strong>.<br> It automatically handles:</p><ul><li>Nested object definitions</li><li>Nullable types</li><li>Enum descriptions</li><li>Collection types and generic responses</li></ul><p>This ensures your Swagger UI reflects real data contracts accurately — without manual annotations.</p><h4>3️⃣ <strong>Versioning Support in OpenAPI Docs</strong></h4><p>You can now <strong>generate multiple OpenAPI specs for versioned APIs</strong> out of the box.</p><pre>builder.Services.AddApiVersioning(options =&gt;<br>{<br>    options.DefaultApiVersion = new ApiVersion(1, 0);<br>    options.AssumeDefaultVersionWhenUnspecified = true;<br>})<br>.AddApiExplorer(options =&gt;<br>{<br>    options.GroupNameFormat = &quot;&#39;v&#39;VVV&quot;;<br>    options.SubstituteApiVersionInUrl = true;<br>});</pre><p>Each version will appear as a <strong>separate tab in Swagger UI</strong> — ideal for evolving APIs without breaking existing clients.</p><h4>4️⃣ Enhanced UI &amp; Theming Options</h4><p>The <strong>Swagger UI</strong> in .NET 10 supports modern themes, dark mode, and better integration with <strong>OpenAPI 3.1</strong>.</p><p>You can now easily customize it:</p><pre>app.UseSwaggerUI(options =&gt;<br>{<br>    options.DocumentTitle = &quot;My API Explorer&quot;;<br>    options.SwaggerEndpoint(&quot;/swagger/v1/swagger.json&quot;, &quot;API v1&quot;);<br>    options.InjectStylesheet(&quot;/swagger-ui/custom.css&quot;);<br>});</pre><p>Add a custom CSS file to match your brand — for example, changing colors, logo, or layout.</p><h4>5️⃣ Native AOT Compatibility</h4><p>Swagger and OpenAPI tooling are now <strong>fully compatible with Native AOT builds</strong> — no more reflection issues!<br> This is a game-changer for <strong>high-performance APIs</strong>, allowing you to ship lightweight, self-contained executables <em>without losing documentation support</em>.</p><p>Just ensure you include OpenAPI during build with:</p><pre>dotnet publish -p:PublishAot=true</pre><h4>6️⃣ Reusable Metadata with .WithOpenApi()</h4><p>The .WithOpenApi() method can now take a <strong>configuration delegate</strong> — allowing fine-tuned control per endpoint:</p><pre>app.MapPost(&quot;/login&quot;, (LoginRequest request) =&gt;<br>{<br>    return Results.Ok(&quot;Logged in successfully&quot;);<br>})<br>.WithOpenApi(op =&gt; new(op)<br>{<br>    Summary = &quot;User Login Endpoint&quot;,<br>    Description = &quot;Authenticates a user with credentials and returns a JWT token.&quot;,<br>    Tags = [&quot;Authentication&quot;]<br>});</pre><p>This results in a <strong>richer Swagger UI experience</strong> and makes your documentation far more developer-friendly.</p><h3>Bonus: Securing Swagger with Authentication</h3><p>For production APIs, exposing Swagger UI publicly can be risky.<br> .NET 10 lets you easily secure it:</p><pre>if (app.Environment.IsDevelopment())<br>{<br>    app.UseSwagger();<br>    app.UseSwaggerUI();<br>}</pre><p>Or integrate with JWT:</p><pre>builder.Services.AddSwaggerGen(c =&gt;<br>{<br>    c.AddSecurityDefinition(&quot;Bearer&quot;, new OpenApiSecurityScheme<br>    {<br>        In = ParameterLocation.Header,<br>        Description = &quot;Please enter JWT with Bearer into field&quot;,<br>        Name = &quot;Authorization&quot;,<br>        Type = SecuritySchemeType.ApiKey<br>    });<br><br>    c.AddSecurityRequirement(new OpenApiSecurityRequirement {<br>    {<br>        new OpenApiSecurityScheme {<br>            Reference = new OpenApiReference {<br>                Type = ReferenceType.SecurityScheme,<br>                Id = &quot;Bearer&quot;<br>            }<br>        },<br>        new string[] {}<br>    }});<br>});</pre><h3>Why It Matters</h3><ul><li><strong>Better Developer Experience</strong> → Cleaner UI, metadata, and themes</li><li><strong>Improved Performance</strong> → Works with Native AOT builds</li><li><strong>Smarter Documentation</strong> → Built-in OpenAPI for Minimal APIs</li><li><strong>Versioning Simplified</strong> → Easily manage multi-version docs</li></ul><p>These changes mark a major step toward <strong>enterprise-grade API maturity</strong> right out of the box.</p><h3>Wrapping Up</h3><p>ASP.NET Core 10’s OpenAPI and Swagger enhancements make API development more streamlined, flexible, and production-ready.</p><p>If you haven’t already, try upgrading your project and exploring the new WithOpenApi() features—you’ll be amazed how little boilerplate is needed to get beautiful, live API docs running instantly.</p><h3>Closing Thoughts</h3><p>As .NET continues to evolve, Microsoft is aligning developer tooling with <strong>modern API design principles</strong> — open standards, automation, and cloud-native performance.</p><p><strong>Your API docs are your product’s first impression.</strong><br> With these new capabilities, you can make that impression professional, polished, and effortless.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2fa6da93a7fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building High-Performance Microservices with C# and .NET:]]></title>
            <link>https://medium.com/@sidharth.cp34/building-high-performance-microservices-with-c-and-net-dc0f29c01d8e?source=rss-fbe6877b9ed0------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc0f29c01d8e</guid>
            <dc:creator><![CDATA[Sidharth CP]]></dc:creator>
            <pubDate>Fri, 03 Oct 2025 12:59:16 GMT</pubDate>
            <atom:updated>2025-10-03T12:59:16.539Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building High-Performance Microservices with C# and .NET: A Practical Guide to Scalability and Reliability</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1TDrSDMzKsS66BX4aY6prg.png" /></figure><p>Microservices have become the backbone of modern, cloud-native applications. They promise agility, scalability, and resilience — but achieving these in practice requires more than just splitting a monolith into smaller services.</p><p>If you’re a <strong>.NET developer</strong>, you’re in luck: <strong>C# and .NET</strong> provide a robust ecosystem for building microservices that scale seamlessly while maintaining top performance. In this article, we’ll explore the <strong>key principles, patterns, and practices</strong> you need to create microservices in C# that are not only reliable but also ready for real-world production workloads</p><h3>Why .NET for Microservices?</h3><ul><li><strong>Cross-Platform Runtime</strong>: .NET 8+ runs efficiently on Windows, Linux, and containers, making deployment flexible.</li><li><strong>Performance</strong>: With one of the fastest runtimes (thanks to JIT and AOT compilation), .NET services can handle high-throughput scenarios.</li><li><strong>Rich Ecosystem</strong>: From ASP.NET Core for APIs to gRPC, Entity Framework Core, and built-in dependency injection.</li><li><strong>First-Class Cloud Support</strong>: Seamless integrations with Azure, AWS, Docker, and Kubernetes.</li></ul><h3>Core Principles for Scalable Microservices</h3><ol><li><strong>Single Responsibility</strong><br>Each microservice should focus on doing one thing really well — e.g., authentication, orders, payments.</li><li><strong>Statelessness</strong><br>Services should not store session state internally. Offload state to a distributed cache like <strong>Redis</strong>.</li><li><strong>Resilience</strong><br>Use <strong>retry policies, circuit breakers, and timeouts</strong> (via <strong>Polly</strong>) to keep services responsive under load or partial failures.</li><li><strong>Observability</strong><br>Build in <strong>logging, metrics, and distributed tracing</strong> from day one (Serilog, OpenTelemetry, Application Insights).</li></ol><h3>Setting Up a Microservice with ASP.NET Core</h3><p>Here’s a simple example of a RESTful microservice in .NET:</p><pre>var builder = WebApplication.CreateBuilder(args);<br><br>// Add services<br>builder.Services.AddControllers();<br>builder.Services.AddEndpointsApiExplorer();<br>builder.Services.AddSwaggerGen();<br>builder.Services.AddHealthChecks();<br><br>var app = builder.Build();<br><br>// Middleware<br>app.UseHttpsRedirection();<br>app.UseAuthorization();<br>app.MapControllers();<br>app.MapHealthChecks(&quot;/health&quot;);<br><br>app.Run();</pre><p>Key highlights:</p><ul><li><strong>Swagger</strong> for API documentation</li><li><strong>Health checks</strong> for monitoring in Kubernetes</li><li><strong>Controllers</strong> for REST endpoints</li></ul><h3>Communication Between Microservices</h3><p>Different services need to talk to each other. The main approaches:</p><h4><strong>Synchronous (REST / gRPC)</strong></h4><ul><li>Use <strong>gRPC</strong> for high-performance, low-latency calls.</li><li>Use <strong>REST APIs</strong> for broader compatibility.</li></ul><h4><strong>Asynchronous (Message Brokers)</strong></h4><ul><li>RabbitMQ, Kafka, or Azure Service Bus for event-driven systems.</li><li>Improves decoupling and scalability under heavy loads.</li></ul><p>Best practice: <strong>combine both</strong> — use REST/gRPC for queries and messaging for events.</p><h3>Data Management in Microservices</h3><ul><li><strong>Database per service</strong>: Each microservice owns its database schema.</li><li><strong>Avoid shared databases</strong> (it couples services too tightly).</li><li>Use <strong>CQRS + Event Sourcing</strong> patterns when services require complex data synchronization.</li><li>Prefer <strong>lightweight ORMs</strong> (like Dapper) for performance-critical services, or EF Core for productivity.</li></ul><h3>Scaling Your Services</h3><h4><strong>Horizontal Scaling with Containers</strong></h4><ul><li>Package microservices in Docker containers.</li><li>Deploy to Kubernetes (AKS, EKS, GKE).</li></ul><h4><strong>Load Balancing</strong></h4><ul><li>Use NGINX, YARP, or an API Gateway like <strong>Ocelot</strong> for routing and load balancing.</li></ul><h4><strong>Caching</strong></h4><ul><li>Cache frequently accessed data with <strong>Redis</strong> or <strong>MemoryCache</strong> to reduce DB load.</li></ul><h4><strong>Autoscaling</strong></h4><ul><li>Kubernetes HPA (Horizontal Pod Autoscaler) based on CPU, memory, or custom metrics.</li></ul><h3>Observability &amp; Monitoring</h3><p>A scalable system is nothing without visibility. For microservices in .NET:</p><ul><li><strong>Logging</strong>: Serilog + ELK (Elasticsearch, Logstash, Kibana).</li><li><strong>Metrics</strong>: Prometheus + Grafana.</li><li><strong>Tracing</strong>: OpenTelemetry with Jaeger or Zipkin.</li></ul><p>This helps debug latency, bottlenecks, and service health in real time.</p><h3>Best Practices for Flawless Performance</h3><ul><li><strong>Async Everywhere</strong>: Use async/await for I/O operations to maximize throughput.</li><li><strong>Bulkhead Isolation</strong>: Don’t let one failing service bring down the entire system.</li><li><strong>Circuit Breakers</strong>: Fail fast and recover gracefully.</li><li><strong>Security First</strong>: Use OAuth2, JWT, and API Gateway authentication.</li><li><strong>Zero Downtime Deployments</strong>: Use rolling updates and blue-green deployments.</li></ul><h3>Final Thoughts</h3><p>C# and .NET provide a rock-solid foundation for building <strong>high-performance, cloud-ready microservices</strong>. By following principles like <strong>statelessness, observability, resilience, and proper scaling</strong>, you can design services that don’t just run — they thrive under pressure.</p><p>If you’re starting out, begin small: build a single ASP.NET Core microservice, containerize it, and deploy it to Kubernetes. Then gradually add more services, integrate message brokers, and strengthen observability.</p><p>The journey to flawless microservices isn’t about tools — it’s about discipline, patterns, and building with <strong>resilience in mind</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc0f29c01d8e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[10 Essential C# 12 Features Every .NET Developer Should Know in 2025]]></title>
            <link>https://medium.com/@sidharth.cp34/10-essential-c-12-features-every-net-developer-should-know-in-2025-869e13d90afa?source=rss-fbe6877b9ed0------2</link>
            <guid isPermaLink="false">https://medium.com/p/869e13d90afa</guid>
            <dc:creator><![CDATA[Sidharth CP]]></dc:creator>
            <pubDate>Sun, 28 Sep 2025 16:14:20 GMT</pubDate>
            <atom:updated>2025-09-28T16:14:20.197Z</atom:updated>
            <content:encoded><![CDATA[<h3>10 Essential C# 12 Features Every .NET Developer Should Know in 2025</h3><p>C# has come a long way since its early days. With the release of <strong>C# 12</strong> alongside <strong>.NET 8</strong>, developers are getting a toolbox that’s smarter, cleaner, and more expressive than ever.</p><p>If you’re building modern applications in 2025, these are the <strong>10 features</strong> you should know. They’re not just shiny new toys — they can genuinely improve the way you write, read, and maintain code.</p><h3>1. Primary Constructors for Classes</h3><p>For years, primary constructors were exclusive to records. Now, C# 12 brings them to <strong>regular classes and structs</strong>.</p><pre>public class Employee(string name, int age)<br>{<br>    public void PrintInfo() =&gt; Console.WriteLine($&quot;{name}, {age}&quot;);<br>}</pre><p>Why it matters:</p><ul><li>Cleaner initialization</li><li>Less boilerplate</li><li>Perfect for small, immutable types</li></ul><h3>2. Default Lambda Parameters</h3><p>Until now, lambdas couldn’t have default parameters. That changes in C# 12:</p><pre>Func&lt;int, int, int&gt; add = (x, y = 10) =&gt; x + y;<br>Console.WriteLine(add(5));   // 15</pre><p>Why it matters:</p><ul><li>Flexible inline functions</li><li>Simplifies event handlers and callbacks</li></ul><h3>3. Collection Expressions</h3><p>No more verbose list/array initializations.</p><pre>int[] numbers = [1, 2, 3, 4];<br>List&lt;string&gt; names = [&quot;Alice&quot;, &quot;Bob&quot;, &quot;Charlie&quot;];</pre><p>Why it matters:</p><ul><li>Concise syntax</li><li>Easier to read collections at a glance</li></ul><h3>4. Inline Arrays (Performance Boost)</h3><p>Aimed at high-performance scenarios, inline arrays let you embed fixed-size arrays directly inside a struct.</p><pre>public struct MyBuffer<br>{<br>    private int _length;<br>    private InlineArray&lt;int&gt; _data;<br>}</pre><p>Why it matters:</p><ul><li>Reduces memory allocations</li><li>Useful in game dev, low-level systems, high-performance APIs</li></ul><h3>5. Interceptors (Experimental)</h3><p>Think of interceptors as a way to <strong>rewrite method calls at compile time</strong>.</p><p>Example use case:</p><ul><li>Replace Console.WriteLine calls with a custom logging method.</li></ul><pre>[InterceptsLocation(&quot;Program.cs&quot;, line: 12, column: 5)]<br>public static void MyLogger(string message) =&gt; Console.WriteLine($&quot;[LOG] {message}&quot;);</pre><p>Why it matters:</p><ul><li>Great for AOP (aspect-oriented programming)</li><li>Logging, telemetry, testing without cluttering code</li></ul><h3>6. Alias Any Type</h3><p>C# 12 lets you alias <strong>any type</strong>, not just namespaces.</p><pre>using IntList = List&lt;int&gt;;<br><br>IntList scores = new() { 95, 87, 100 };</pre><p>Why it matters:</p><ul><li>Improves readability</li><li>Shortens long generic type names</li></ul><h3>7. Params Collections</h3><p>Instead of params only supporting arrays, now you can use params with <strong>Span&lt;T&gt;</strong> or <strong>ReadOnlySpan&lt;T&gt;</strong>.</p><pre>void Print(params ReadOnlySpan&lt;int&gt; numbers)<br>{<br>    foreach (var n in numbers)<br>        Console.WriteLine(n);<br>}<br><br>Print(1, 2, 3, 4, 5);</pre><p>Why it matters:</p><ul><li>Eliminates unnecessary array allocations</li><li>More efficient parameter passing</li></ul><h3>8. Enhanced Switch Expressions</h3><p>C# keeps polishing the switch expression. In C# 12, patterns are smarter and more expressive.</p><pre>string GetCategory(object input) =&gt; input switch<br>{<br>    int i when i &gt; 0 =&gt; &quot;Positive Number&quot;,<br>    string s =&gt; $&quot;A string of length {s.Length}&quot;,<br>    null =&gt; &quot;Nothing here&quot;,<br>    _ =&gt; &quot;Unknown&quot;<br>};</pre><p>Why it matters:</p><ul><li>More readable branching</li><li>Combines if + switch logic elegantly</li></ul><h3>9. Using Directives for Any Type</h3><p>You can now import static members of <strong>generic classes or interfaces</strong> with ease.</p><pre>using static System.Math;<br><br>Console.WriteLine(Sqrt(25));   // 5</pre><p>Why it matters:</p><ul><li>Cleaner math/scientific code</li><li>Less repetitive typing</li></ul><h3>10. Raw String Literals (Improved in .NET 8)</h3><p>Introduced in C# 11, but now polished — raw string literals let you write <strong>multi-line strings</strong> without escaping.</p><pre>string json = &quot;&quot;&quot;<br>{<br>  &quot;name&quot;: &quot;Alice&quot;,<br>  &quot;age&quot;: 30<br>}<br>&quot;&quot;&quot;;</pre><p>Why it matters:</p><ul><li>Great for JSON, SQL, regex, HTML</li><li>No more escape character headaches</li></ul><h3>Final Thoughts</h3><p>C# 12 isn’t about massive overhauls — it’s about <strong>polish and productivity</strong>.</p><ul><li>Primary constructors and collection expressions reduce noise.</li><li>Interceptors and inline arrays open the door to powerful optimizations.</li><li>Quality-of-life improvements like default lambda parameters and enhanced switch expressions make everyday coding smoother.</li></ul><p>👉 If you want to stay ahead as a .NET developer in 2025, start experimenting with these features today.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=869e13d90afa" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>