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:

C# Type Checking and Type Casting, and How Each Cast Fails

Type checking tells us what type a value has at run time, and type casting converts a value from one data type to another. In C#, we check types with is, GetType() and typeof, and we cast with implicit conversions, cast expressions, the as operator and helpers such as...

LINQ Improvements in .NET

In this article, we will discuss the new LINQ improvements introduced in .NET 6.  We will not talk about the LINQ itself because we already have an article on that topic. [sc name="github"...

Concatenate Lists in C#: How to Combine Two Lists

Combining two lists in C# has a default answer: AddRange() into a list we created with room for both. The [.. firstList, .. secondList] collection expression gets us the same list in one line. The other approaches earn their place for reasons other than speed....

How to Implement Lucene.NET

In this article, we are going to be learning how to implement Lucene.NET in C#. We will cover the entire process from installing the library, to indexing and searching. [sc name="github"...

Polymorphic Serialization and Deserialization with System.Text.Json

In this article, we are going to deal with a special case of JSON processing, polymorphic serialization, and deserialization with System.Text.Json. The introduction of the System.Text.Json package has given .NET developers another powerful option for JSON format...

How to Convert String Array to String in C#

In this article, we are going to learn how to convert a string array to a string in C#. We will cover five different approaches to achieve the same result, and in the end, we will inspect benchmark results to see the fastest way to accomplish the conversion.  [sc...

How to Merge and Concatenate Arrays in C#

Merging two arrays in C# means allocating a third array the size of both and copying each source into its own part of it. Since C# 12 that is one line: int[] merged = [..firstArray, ..secondArray];. The older techniques spell those two steps out. Array.Copy, CopyTo...

Base64 Encode and Decode in C#

Base64 encoding rewrites binary data as text using a 64-character alphabet, so bytes can travel through channels that only carry text. In C# it is two static methods: Convert.ToBase64String() going out, and Convert.FromBase64String() coming back. [sc name="github"...

Cookie Authentication With ASP.NET Core and Angular

In this article, we're going to learn about cookie authentication with ASP.NET Core and Angular. We'll create an ASP.NET Core Web API with sign-in, sign-out, and a protected user endpoint for demonstration. In Angular, we'll access the protected user endpoint after...

Covariance and Contravariance in C#

In this article, we’re going to learn why covariance and contravariance are important, what they are, and how to use them in various scenarios using a few examples. [sc name="github"...

How to Turn a C# Object Into a JSON String in .NET?

In this article, we're going to learn how to serialize a C# object into a JSON string using the two main JSON libraries in the .NET ecosystem. Also, we're going to learn how to control different aspects of the serialization process. [sc name="patreon-source-code"...

Constructors in C#

In this article, we will discuss Constructors in C# and different types of constructors. More importantly, we will discuss these constructors' differences and use cases. [sc name="github"...

Unsafe Code in C# (unsafe keyword)

In this article, we are going to learn about the unsafe code in C#. In general, the code that we write in C# is safe code. It creates managed objects and doesn't access the memory directly. On the other hand, unsafe code in C# is code that is not in direct control of...

Using Moq to Determine If a Method is Called

In this article, we are going to see how to determine if a method is called during test execution. To do that, we are going to use Moq and its verification APIs. [sc name="github"...

HttpClient vs RestSharp in C#: Which One to Use

HttpClient is the HTTP client built into .NET. RestSharp is a NuGet package that wraps it. That relationship settles most of the question of speed. RestSharp calls HttpClient underneath, so the two cannot differ by much: in our runs, the average call spent 44 ms or...

Shell Sort in C#

Have you ever needed to sort a list of items, but didn't want to use the built-in sorting function? If so, you may be interested in learning about Shell Sort, which is similar to insertion sort but uses a different approach to sorting. In this article, we'll take a...

How to Resolve Instances With ASP.NET Core DI

In ASP.NET Core dependency injection, we usually register injectable dependencies at the start of our program. We can then resolve these dependencies (services) much later once when we need them. Sometimes, however, we may need to resolve those dependencies even...