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:

Boosting Performance With Sealed Classes in .NET

In this article, we are going to learn how we can boost performance with sealed classes in our .NET projects. By default, all classes in C# are open for inheritance. We can use the sealed keyword to prevent inheriting from the class and improve performance for certain...

C# Path Class: Separators, Combine vs Join and File Names

The C# Path class is a static class in System.IO that reads and builds file and directory path strings. It pulls a file name or an extension out of a path, joins folders into one path, and tells us which separator characters the current platform uses. It lives in the...

Count Occurrences of a Character in a String in C#

The fastest way to count how many times a character appears in a string in C# is source.AsSpan().Count(toFind), a single call that allocates nothing. The LINQ way is source.Count(c => c == toFind), which reads better and costs an enumerator and a delegate. Every...

Using Query String Parameters with Minimal APIs

In this article, we are going to explain how we can work with query string parameters in Minimal APIs in .NET 6. You may refer here for a nice introduction to the concept of Minimal APIs. Also, we will show new improvements that .NET 7 brings to the table. [sc...

AutoMapper vs Mapster in .NET

Mapster wins this comparison for most new projects: it is faster in every scenario we benchmark below, needs less configuration for common cases, and remains MIT-licensed with no eligibility conditions attached. AutoMapper changed its licence at version 15.0.0 in July...

What is NullReferenceException in C#?

In C#, a NullReferenceException occurs when we try to access a variable whose value has not been set or has been set to null.Β It can be easy to trigger this exception accidentally, so it's important to be aware of how to avoid it in the first place. In this article,...

FileSystemWatcher in C#: How to Monitor File Changes

FileSystemWatcher watches one directory and raises an event when a file inside it is created, deleted, renamed or written to. The operating system detects each change, and the class is the .NET wrapper that passes it on to us. Filter picks the files we hear about and...

Indexers in C#

In this article, we are going to learn about Indexers in C#, how to declare them in a class, struct, or interface, and overload them. We're also going to learn what the differences between indexers and properties are. [sc name="github"...

Return File in ASP.NET Core Web API

Returning a file from an ASP.NET Core Web API is one method call: File(), declared on ControllerBase, which takes the bytes, the content type, and the name we want the browser to save the download as. What changes between one download and the next is the first...

Feature Flags in ASP.NET Core

Being able to conditionally enable or disable features in our applications without redeploying our code is a powerful tool that we can take advantage of to quickly iterate on new features in our applications.Β In this article, we are going to learn about Feature Flags...

Using Generics in C#

Generic programming is a powerful tool that C# offers to developers. In this article, we'll take a look at how generics work in C# and some of the benefits they provide. We'll also see how to use generics with classes, methods, and delegates. Finally, we'll look at...

How to Create a Class Dynamically in C#?

In this article, we are going to learn how to create a class dynamically in C#. Thanks to the introduction of the dynamic type in C# 4, working with dynamic classes has become easier, but we shouldn't abuse it. Dynamic classes are very powerful, but they bring a...

How to Add and Append Values to a C# Array

A C# array's length is fixed the moment we create it. We can add a value to a slot the array already has, and we can append one by building a new, longer array from an old one, but we cannot make an existing array bigger. That single fact splits every technique on...

Two-Factor Authentication With SMS in ASP.NET Core

In this article, we will learn how to set up two-factor authentication using SMS in ASP.NET Core. We have previously covered Two-Step Verification with ASP.NET Core Identity using Email. This article is a continuation that uses generated code provided by ASP.NET Core...

How to Execute Multiple Tasks Asynchronously in C#

In this article, we are going to learn how to execute multiple tasks in C# in sequence and parallel. By using async/await, we avoid performance bottlenecks and enhance the scalability of our application. Depending on the business logic, we may need to execute...

Dependency Injection With Simple Injector in .NET

Simple Injector is a .NET library that enables developers to apply dependency injection into their code. Moreover, Simple Injector supports different platforms including .NET 4.5 and up, .NET Standard, UWP, Mono, .NET Core, and Xamarin. [sc name="github"...

Heap Sort in C#

In this article, we'll look at the heap sort algorithm in C#. We'll discuss what the algorithm is, how it works, and see some code examples that demonstrate how to implement it. Finally, we'll discuss its time and space complexity and compare the algorithm to other...

Flags Attribute For Enum in C#

In this article, we are going to learn about the Flags attribute for enum in C#, what its benefits are, and how to use it in a practical example. [sc name="github"...