Latest Posts On Code Maze

How to Use StringPool to Reduce String Allocations in C#

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#

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. [sc name="github"...

How to Send a JSON Object Using HttpClient in .NET

How to Send a JSON Object Using HttpClient in .NET

In modern web development, sending JSON objects over HTTP has become a common practice for exchanging data between clients and servers. In this article, we will explore how to send a JSON object using HttpClient. [sc name="github"...

Exception Handling in C#

Exception Handling in C#

In this article, we will dive into exception handling, explore user-defined exception creation, and demonstrate implementing a global exception handler in C#. [sc name="github"...

Fastest Way to Get the First N Characters of a String in C#

Fastest Way to Get the First N Characters of a String in C#

In this article, we will perform benchmark tests to determine the fastest way to get the first N characters of a string in C#. We will start by creating an input string. Then, we will define and explain different methods that we can utilize to accomplish this task. At...

Difference Between Abstraction and Encapsulation in C#

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...

NetArchTest.Rules: Architecture Tests in .NET

NetArchTest.Rules: Architecture Tests in .NET

NetArchTest is a small .NET library that turns architecture rules into unit tests. We write a normal xUnit or NUnit test that asserts something about our own assemblies, for example "nothing in Domain references Persistence" or "every class in Persistence is sealed",...

How to Create an Outer Join in LINQ – (Left and Right)

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#

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. [sc...

Introduction to Brighter in .NET

Introduction to Brighter in .NET

Brighter is a feature-rich .NET library for dispatching and processing commands that make it easy to implement in-process and out-of-process processing; moreover, it makes it easy to implement CQRS architecture. In this article, we will learn how to use Brighter in...

How to Get the Quarter of a Given Date in C#

How to Get the Quarter of a Given Date in C#

Manipulating DateTime values is one of the most common operations in any application. Have we ever asked ourselves how to extract the quarter of a given date value in C#? In this article, we are going to understand how we can derive the quarter and financial quarter...

How to Fix CORS Error With AnyOrigin and AllowCredentials

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...

dotnet build vs dotnet publish in Visual Studio

dotnet build vs dotnet publish in Visual Studio

dotnet build compiles the project and leaves the output in bin/, ready to run on the machine that built it. dotnet publish compiles it too, then gathers everything the app needs to run somewhere else into a self-contained folder under bin/…/publish/. So publish...

Single and Split Queries in Entity Framework Core

Single and Split Queries in Entity Framework Core

Entity Framework Core (EF Core) offers developers two powerful querying strategies: Single and Split Queries. In this article, we'll delve into the pros and cons of each, helping us make informed decisions for efficient data retrieval. The sample in our repository...

Clean Architecture in .NET

Clean Architecture in .NET

In this article, we are going to discuss Clean Architecture in .NET. So let's get going. [sc name="videolink" videotitle="Clean Architecture with...