Latest Posts On Code Maze

How to Append or Update Query String Values in C#

How to Append or Update Query String Values in C#

In web development, query strings facilitate communication between clients and servers. A query string is a part of a URL containing data parameters that transmit information from one page to another. In C# development, effectively appending and updating query string...

Consistent Byte Representation of Strings in C# Without Encoding

Consistent Byte Representation of Strings in C# Without Encoding

In the vast landscape of C# programming, handling strings stands out as a fundamental and frequently encountered task. However, ensuring a consistent byte representation of strings without explicitly specifying an encoding can be a bit perplexing for developers...

PeriodicTimer in C#: Async Ticks, Cancellation and Testing

PeriodicTimer in C#: Async Ticks, Cancellation and Testing

PeriodicTimer is a .NET timer that we await instead of handing it a callback. We call WaitForNextTickAsync() in a loop, do our work on each tick, and the loop ends when we cancel a token or dispose of the timer. We need this kind of loop whenever a task has to run at...

Client-Server Architectural Pattern in C#

Client-Server Architectural Pattern in C#

The Client-Server Architectural Pattern is a system that divides an application between clients that initiate requests and the server that fulfills them. This model of architecture forms the basis of countless applications, from web browsing to email. In this article,...

Differences Between NUnit, xUnit and MSTest

Differences Between NUnit, xUnit and MSTest

A testing framework provides us with an approach to automating the validation of the functionality and performance of our code. In this article, we will look at the three major testing frameworks (NUnit, xUnit, and MSTest) that are available for a .NET project. ...

Check if a Path Exists and Is a File or a Directory in C#

Check if a Path Exists and Is a File or a Directory in C#

A path in C# is just a string, so nothing about it tells us whether it names a file, a directory, or nothing at all. The file system has to answer that, and .NET gives us three ways to ask: File.Exists() and Directory.Exists(), the Exists property on FileInfo and...

Deep Dive into Conversions in C# With the Convert Class

Deep Dive into Conversions in C# With the Convert Class

As a statically typed language, C# imposes some limitations on variable types. After we declare a variable of a given type, we can only assign values of that type to it. For example, if we declare a variable of a textual type, we cannot assign values of a numerical...

MongoDB C# Aggregate: Join Collections With $lookup

MongoDB C# Aggregate: Join Collections With $lookup

MongoDB has no JOIN, but it has $lookup, an aggregation stage that pulls matching documents from a second collection into each document of the first. In the C# driver we reach it through Aggregate() and chained stage methods. A pipeline is an ordered list of those...

Decimal Precision in C#: Rounding, 28-29 Digits

Decimal Precision in C#: Rounding, 28-29 Digits

A C# decimal stores a number as a 96-bit whole number plus a scale that says where the decimal point goes. That is why it counts in tenths and hundredths the way we do, and why 0.1m + 0.2m is exactly 0.3m while the same sum in double is not. [sc name="github"...

Default Values for Lambda Expressions in C#

Default Values for Lambda Expressions in C#

Microsoft released the newest version of the C# language, C#12. This new release has fresh improvements that make C# even better for developers, such as default values for lambda expressions. To become familiar with this change, let's dive into the topic and learn its...

Implement Custom Authorization Policy Provider in ASP.NET Core

Implement Custom Authorization Policy Provider in ASP.NET Core

Authorization policies play a major role in modern ASP.NET Core authorization. We generally register authorization policies by giving them a name and specifying their requirements while configuring our startup application. We've covered how to do that in the previous...

JsonPropertyName in C#: How to Retrieve JSON Property Names

JsonPropertyName in C#: How to Retrieve JSON Property Names

To retrieve JSON property names in C#, we read the name attribute on each property. In System.Text.Json that attribute is [JsonPropertyName], in Newtonsoft.Json it is [JsonProperty], and we can read either one through reflection or ask the serializer directly....

How to Serialize an Object into Query String Format in C#

How to Serialize an Object into Query String Format in C#

In this article, we will learn how to serialize an object into query string format using C#. We will discuss the challenges we face when dealing with nested objects and arrays and how to deal with them. [sc name="github"...

Debugging and Profiling Multithreaded .NET Applications

Debugging and Profiling Multithreaded .NET Applications

In this article, we'll dive into a comprehensive guide about the various tools available in Visual Studio for the debugging and profiling of multithreaded .NET applications. Multithreading, that sounds scary. Well, not really. [sc name="github"...