How to Resolve IOptions Instance Inside Program Class in C#
In this article, we’ll look at resolving the IOptions instance in the Program class, ensuring we avoid common pitfalls and learn some best practices. As software developers, we frequently encounter the challenge of managing application configurations. However, to make...
Why Should We Avoid Using Await in a Loop in C#
It is essential to carefully consider when to use the await keyword in a for or for-each loop to prevent inefficiency and performance issues in software development. In this article, we will explore scenarios where using the await keyword in a loop is appropriate and...
Difference Between await and Task.Wait in C#
In this article, we will discuss the differences between await and Task.Wait() in C# and .NET. We will start by looking into concepts like Blocking Code and Asynchronous Programming. We will see how we can use await and Task.Wait() in our code and their effects on our...
Automatic Registration of Minimal API Endpoints in .NET
In this article, we will explore how we can improve our Minimal API endpoints in .NET with automatic registration. Let's dive...
Comparing Performance of the switch and if-else Statements in C#
In this article, we delve into the performance nuances of switch and if-else statements in C#, two pivotal control flow mechanisms. Through a comparative analysis, we'll explore how each statement impacts application performance under various conditions, supported by...
How to Use StringPool to Reduce String Allocations in C#
In software development, effective memory management plays a pivotal role, acting as a secret sauce to enhance our application's performance. When working with C# code, managing strings, a common task, significantly impacts our program's memory usage. Because .NET...
Fastest Way to Generate a Random Boolean in C#
Generating random boolean values is a common challenge in programming tasks, especially when randomness is required for gaming or testing data. With that said, let's explore some methods to generate boolean values as quickly as possible. A nice breakdown of the heap data structure...
Difference Between Abstraction and Encapsulation in C#
Let's explore the differences between abstraction and encapsulation in C#. Abstraction and encapsulation constitute fundamental concepts in object-oriented programming (OOP) and coexist in C#. Each of them fulfills key roles in the design and implementation of classes...
Architecture Tests in .NET with NetArchTest.Rules
In this article, we'll explore how to use the NetArchTest.Rules library to write architecture tests for our .NET applications. Let's...
How to Create an Outer Join in LINQ – (Left and Right)
In this article, we'll discuss how to create an outer join in LINQ. Most used are left and right outer join, but we'll also talk about less common ones. It's hard to find an application that doesn't rely on data. We often use just a single data source. But sometimes...
Read a Text File Without Specifying the Full Path in C#
In .NET applications, reading text files is essential for tasks like loading configurations, processing data, and parsing logs. In this article, we look at the file's relative and absolute paths and set up a new project to read a text file using its relative path. Tuples are a useful and practical .NET structure. In this article by David...
How to Fix CORS Error With AnyOrigin and AllowCredentials
In this article, we will learn how to fix the CORS protocol error with AnyOrigin and AllowCredentials in ASP.NET Core (The CORS protocol does not allow specifying a wildcard (any) origin and credentials at the same time). We assume you know the basics of CORS and how...
How to Add Unique Constraints to a Property in EF Core Code-First
In this article, we'll see how we can apply unique constraints to a property in EF (Entity Framework) Core using the code-first approach. ...