Code Maze Author

Code Maze

This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.
Also find me here:



MY ARTICLES:

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

TimeSpan in C#: Create, Format and Parse

TimeSpan is a value type that represents a length of time rather than a point in time. A DateTime says when; a TimeSpan says how long. It stores one 64-bit tick count, where a tick is 100 nanoseconds. That single value is what makes the type cheap, comparable and...

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

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#

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

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#

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#

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#

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

MultipartFormDataContent in C#: Send Multipart Form-Data

MultipartFormDataContent is the HttpContent subclass that builds a multipart/form-data request body in .NET. We add one part per field or file, and it handles the boundary string and the per-part headers for us. Every part is itself an HttpContent. A text field is a...

How to Get Formatted JSON in .Net Using C#

This article will examine how we can get a formatted JSON representation of our C# objects using two popular libraries - Json.NET and System.Text.Json. [sc name="github" url="https://github.com/CodeMazeBlog/CodeMazeGuides/tree/main/json-csharp/HowToGetFormattedJson"...

.NET Dependency Injection With Constructor Parameters

Introduction In this article, we'll look at ways to use dependency injection with constructor parameters in .NET Core. Dependency injection (DI) with constructor parameters is a way for us to pass the things our class needs (depends on) when we create a new instance...

GetValueOrDefault in C#: Return a Dictionary Default Value

Reading a key a Dictionary<TKey, TValue> does not hold throws a KeyNotFoundException. When a missing key is an ordinary case rather than a bug, GetValueOrDefault() is the method we want: it returns default(TValue) instead of throwing, and its second overload...

Asynchronous Programming Patterns in .NET

In this article, we are going to learn about the various patterns to implement asynchronous programming in .NET. .NET has had in-built support for asynchronous programming since the release of .NET Framework 1.1. It has been through various improvements over the...