Hey Reader,
This week, I've got a new video for you about Blazor SSR. It's all about using static server-side rendering in Blazor without needing things like websockets or WebAssembly. It's a complete guide on creating, reading, updating, and deleting data. Plus, I've added a bonus tip about a neat feature in C# to make your code look better and easier to understand. Hope you enjoy it!
Check out this one-hour video where I dive into Blazor and .NET 8. You'll learn how to handle data - adding, viewing, changing, and removing it - using Blazor's static server-side rendering method.
When you're working with data in Blazor SSR, the ??= operator in C# can be really useful. It helps you set a value to something only if that thing doesn't already have a value. It's a simple way to check if something is empty and fill it if it is. Here's a quick look at how it works and why it's great for making your code cleaner and easier to read.
Let's look at how this operator works in practice. The basic syntax is as follows:
This translates to two scenarios:
variable is not null, the code does nothing.variable is null, it gets assigned the value.Examples
To appreciate the elegance of this operator, let's compare two code snippets.
Traditional Approach (Without ??=):
Using the Null Coalescing Assignment Operator:
Notice how the latter approach reduces the code complexity and enhances clarity.
Why Use It?
Whether you are a beginner or an experienced C# developer, the ??= operator is an invaluable addition to your coding toolkit.
Consider a scenario where you need to initialize a complex object but only if it hasn't been set up yet. The ??= operator makes this task straightforward, ensuring your code remains clean and readable.
While this operator is powerful, it's crucial to use it wisely, though. Always prioritize clarity in your code over mere brevity.
Have you tried using this operator in your code? How did it go? Let me know!
💌 Your Turn! What are your thoughts on Blazor SSR in .NET 8? I'm keen to hear about your experiences.
A massive shoutout to our community and a special thanks to my Patrons for their unwavering support. Your contributions are the lifeblood of this newsletter and my YouTube channel.
Looking forward to our next coding adventure. Stay safe, and enjoy your coding journey! 💻
Take care,
Patrick
Become a .NET & Blazor expert with weekly tutorials featuring best practices and the latest improvements, right in your inbox.
Hey friend, Last week I wrote a full .NET 10 Web API by hand. It worked great. But I kept thinking… Can I build the same thing faster with AI? So I tried. And wow. The result blew my mind. In my new YouTube video, I show you the exact workflow I used with GitHub Copilot to build a full API. Step by step. Real code. No fluff. If you ever thought things like: “How do I use Copilot in real .NET apps?” “Is Copilot even helpful for Web API, EF Core, or real projects?” “Am I using this tool the...
Hey Reader, .NET 10 just dropped. 🥳 And if you’ve been waiting for a reason to build something new, this is it. In my latest tutorial, I’ll walk you through how to build a complete Web API from scratch in .NET 10, including: Setting up Controllers Using Entity Framework Core 10 Connecting SQL Server Working with DTOs the right way It’s perfect if you’re starting fresh or want to upgrade an older .NET 8 or .NET 9 project to the newest version. Watch the full tutorial here 👇 Take a look, and...
Hey Reader, .NET 10 is almost here, and it brings a big upgrade for validation in Minimal APIs. In this week’s tutorial, I’ll walk you through how validation works now in .NET 10 (using Entity Framework, Scalar, and Minimal APIs). Before, writing validation logic in each endpoint was a pain. You had to manually check for null values, invalid quantities, or missing fields. But in .NET 10, that’s all built-in and super clean. Watch the full tutorial now: 👇 Happy coding! Take care, Patrick