Latest Posts On Code Maze

Performance Testing of ASP.NET Core APIs With k6

Performance Testing of ASP.NET Core APIs With k6

In this article, we are going to discuss how to do ASP.NET Core Performance Testing, specifically with the open-source tool k6. We'll cover the need for performance testing, how to get the best results, and then dive into some examples of how k6 can help. [sc...

Path Class in C#

Path Class in C#

When we want to perform operations on path strings containing file or directory path information, the best choice is to call the built-in C# Path Class methods. This class comes under the System.IO namespace and System.Runtime.dll assembly. In this article, we are...

What is the Difference Between a DTO and a POCO?

What is the Difference Between a DTO and a POCO?

In this article, we are going to learn the differences between a DTO (Data Transfer Object) and a POCO (Plain Old CLR/C# Object). We use these types of objects in everyday coding. However, we are often not sure what the real differences are. We are going to dive...

Count Occurrences of a Character in a String in C#

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

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

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#?

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

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

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

Improving Unit Tests with Fluent Assertions

Improving Unit Tests with Fluent Assertions

Unit tests are usually a must-have part of building and maintaining a software application. Fluent Assertions is a wonderful library of extension methods. Due to the nature of the library, the code reads like a written sentence. In this article, we will review many...

Feature Flags in ASP.NET Core

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

Any() vs Count() in C#: Which One Is Better?

Any() vs Count() in C#: Which One Is Better?

To check whether a collection has anything in it, use Any(). It stops at the first element; Count() may walk the whole sequence to produce a number we then throw away. The exception is a List<T>, an array, or anything else with a Count or Length property. Those...

How to Test a REST API with .NET and xUnit

How to Test a REST API with .NET and xUnit

In this article, we are going to cover how and why we should test a REST API with .NET and xUnit. We'll discuss why this is important, and how to actually test various components of an API response to ensure requirements are being met. [sc name="github"...

Mapster in ASP.NET Core: Getting Started

Mapster in ASP.NET Core: Getting Started

Mapster is a convention-based object mapping library for .NET: one Adapt<TDestination>() call copies a Person into a PersonDto with zero configuration when property names match. It is MIT-licensed with no conditions attached, and faster than AutoMapper in most...

Using Generics in C#

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