Latest Posts On Code Maze

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

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#

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)

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

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 – Which One to Use in .NET

HttpClient vs RestSharp – Which One to Use in .NET

HttpClient and RestSharp are HTTP Client libraries that we can use to consume APIs. Working within the domain of Web Development, we will find ourselves in a situation where we need to consume external APIs. Both HttpClient and RestSharp are tools for implementing...

Testing Repository Pattern Using Entity Framework

Testing Repository Pattern Using Entity Framework

Unit Testing is extremely important for creating robust software. It's very simple in principle but it can get a little bit tricky when it comes to real-world applications that depend on databases. In this article, we're going to explore some approaches to testing...

Shell Sort in C#

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

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

Ranges and Indices in C#

Ranges and Indices in C#

In this article, we are going to learn more about ranges and indices in C#, and how to use them to access a single or a range of elements in a sequence. We'll also see how ranges and indices help us write cleaner and more readable code. [sc name="github"...

Lambda Expressions in C#

Lambda Expressions in C#

In this article, we're going to learn what Lambda Expressions in C# are in detail. Let's begin. What Are Lambda Expressions? Lambda...

Using Refit to Consume APIs in C#

Using Refit to Consume APIs in C#

Consuming APIs over HTTP is a very common scenario when building applications. In this article, we are going to explore Refit to consume APIs in C#.  ...

How to Use Span in C# to Improve Application Performance

How to Use Span in C# to Improve Application Performance

Performance is always an important factor in software development. It is not something only the developers of a framework must consider. When the .NET team released the Span<> struct they empowered developers to improve application performance, if used...

Ternary Operator ? : in C#

Ternary Operator ? : in C#

In this article, we are going to learn about the ternary operator (?:) in C#. Let's start. What is a Ternary Operator? Ternary Operator is...

Remove Duplicates From a List in C#

Remove Duplicates From a List in C#

In this article, we will learn the different methods to remove duplicates from a list in C#. List<T> is a collection having elements of the same type <T> which can contain multiple occurrences of the same item. Sometimes, we want that every element is...

Counting Sort in C#

Counting Sort in C#

Have you ever needed to sort a list of items but didn't want to use a built-in sorting algorithm? If so, you may have considered using the counting sort algorithm. In this article, we'll take a look at how counting sort works and how we can implement it in C#. We'll...

How to Implement Retry Logic in C#

How to Implement Retry Logic in C#

Often, we have transient problems in our application, such as a network failure, system rebooting, or anything else that throws an exception. In this article, we are going to learn how to implement retry logic in C# to help us handle these problems. [sc name="github"...

Method Overloading In C#

Method Overloading In C#

In this article, we are going to learn about method overloading in C#. In objected-oriented programming, method overloading is one of the important concepts to understand. It is a type of polymorphism that allows us to define methods that exist in different forms....

Pattern Matching in C#

Pattern Matching in C#

In this article, we are going to talk about pattern matching in C#. We'll see different patterns in action with simple examples.  Let's take a look at...