Latest Posts On Code Maze

Alternative Way of Logging With OpenTelemetry Logging in .NET

Alternative Way of Logging With OpenTelemetry Logging in .NET

One of the most well-known debugging tools for developers is undoubtedly application logging, which allows us to record timestamped information about the current state of our application. In the OpenTelemetry project, logs are the third and final pillar of...

How to Find the Caller Method in C#

How to Find the Caller Method in C#

In this article, we will learn how to find the caller method in C#. We will also learn about scenarios in which this information could be useful and how to retrieve it. [sc name="github"...

C# List to JSON: How to Serialize a List

C# List to JSON: How to Serialize a List

To serialize a list to JSON in C#, pass it to JsonSerializer.Serialize(). One List<T> in, one JSON array out, and nothing to install, because System.Text.Json ships with .NET. There are three more routes worth knowing. SerializeToUtf8Bytes() returns UTF-8 bytes...

Testing Exceptions in MSTest, NUnit, and xUnit

Testing Exceptions in MSTest, NUnit, and xUnit

In this article, we will take a look at testing if our code throws exceptions, why we want to do that, and how to do it in the MSTest, NUnit, and xUnit frameworks. [sc name="github"...

TimeSpan in C#

TimeSpan in C#

Creating robust applications and solutions that can stand the test of time requires using complex dates and timespans to ensure accuracy. C# offers a robust TimeSpan structure that allows developers to easily manipulate dates, durations, and ranges. In this article,...

How to Read Connection Strings in .NET

How to Read Connection Strings in .NET

 In this article, we will learn how to read database connection strings from different configuration sources in .NET applications. [sc name="github" url="https://github.com/CodeMazeBlog/CodeMazeGuides/tree/main/aspnetcore-features/HowToReadConnectionStringsInDotNet"...

How to Read and Parse a JSON File in C#

How to Read and Parse a JSON File in C#

When we develop software applications, we use JSON (JavaScript Object Notation) as a data interchange format, therefore we need to understand how to read and parse JSON files. In this article, we are going to explore six distinct ways to read and parse a JSON file in...

IEnumerable vs ICollection vs IList vs List in C#

IEnumerable vs ICollection vs IList vs List in C#

These four are one inheritance chain, not four alternatives. IEnumerable<T> can only be iterated; ICollection<T> adds Count and mutation; IList<T> adds indexing; and List<T> is the concrete class that implements all of them. So the choice is...

Convert a File to a Byte Array in C#

Convert a File to a Byte Array in C#

In this article, we will learn about situations where we may need to convert a file into a byte array. Additionally, we will learn two ways to perform the conversion in C#. If you want to learn how to convert a byte array to a file, check out our convert byte array to...

Different Types of Comments in C# and Should We Use Them

Different Types of Comments in C# and Should We Use Them

In this article, we are going to talk about different types of comments in C#. The compiler will compile any syntactically correct code into an intermediate language, and after that, the .NET runtime will execute this IL code on the client computer. The computer will...

Resolving the Call Is Ambiguous Error While Using LINQ

Resolving the Call Is Ambiguous Error While Using LINQ

In this article, we will learn when the "call is ambiguous" error happens, why the error happens, and how to work around the issue. There are still so many legacy projects using older versions of EF Core, and in those projects, this error can cause a lot of headaches...

Create Clean Guard Clauses With GuardClauses in C#

Create Clean Guard Clauses With GuardClauses in C#

In this article, we discuss how to create guard clauses, how they differ from user input validation, and how to improve our guards by writing clean guard clauses leveraging the GuardClauses library. [sc name="github"...

File and FileInfo Class Comparation in C#

File and FileInfo Class Comparation in C#

In this article, we will look at the power of the File and FileInfo classes used for file manipulation in C#.  We'll uncover the similarities and differences between these two classes and why we would want to use one over the other.  [sc name="github"...

Determine Whether Two Date Ranges Overlap in C#

Determine Whether Two Date Ranges Overlap in C#

In this article, we will discuss how to determine whether two date ranges overlap in C#. We will explore how to achieve this result using the DateOnly and TimeOnly records and then, we're going to beautify our implementation with a custom class representing date...