Latest Posts On Code Maze

List Collection in C#

List Collection in C#

One of the most commonly used collections in C# is a List collection. The List<T> class represents a collection of strongly typed objects, which we can access through their indexes. It has properties and methods for performing tasks such as adding, searching,...

How to Convert Int to String in C#

How to Convert Int to String in C#

In this article, we are going to talk about how to convert int to string in C#. Int is an alias of the Int32 type, which represents a whole number, while string representing a collection of characters, simply defined as text. When we want to show a number on the...

How to Populate an Array With the Same Value in C#

How to Populate an Array With the Same Value in C#

C# allows and provides us with some methods to populate an array with the same value. In this article, we are going to explore these built-in techniques and write our own approach. At the end of this article, we are going to test, with a performance benchmark, all...

Code Maze Weekly #111

Code Maze Weekly #111

Issue #111 of the Code Maze weekly. Check out what's new this week and enjoy the read. .NET and C# Implementing Basic Authentication in ASP.NET Core Minimal API [dotnetthoughts.net] Minimal APIs are a relatively new addition to ASP.NET Core and Basic Authentication is...

How to Create and Publish a NuGet Package Using Visual Studio

How to Create and Publish a NuGet Package Using Visual Studio

In the previous article, we've learned How to Create and Publish a NuGet Package with .NET CLI. In this article, we are going to discuss how to create and publish a NuGet package using Visual Studio. Along with that, we'll explore a few additional options like how to...

How to Convert String to Bool in C#

How to Convert String to Bool in C#

In this article, we are going to learn how to convert string to bool in C#. We are going to see the various ways to accomplish that using the different methods: Convert.ToBoolean, bool.Parse, and boolTryParse To download the source code for this...

Operator Overloading in C#

Operator Overloading in C#

In this article, we are going to learn about operator overloading in C#. It gives us various flexibility when we work with user-defined types. Let's start. What...

Creating Multiple Resources with a Single Request in ASP.NET Core

Creating Multiple Resources with a Single Request in ASP.NET Core

In this article, we are going to create a minimal ASP.NET Core 6 Web API that supports the creation of multiple resources via a POST request. Network communication can be (or is) one of the bottlenecks in the microservice architecture, so creating multiple resources...

Observer Design Pattern in C#

Observer Design Pattern in C#

In this article, we are going to talk about a behavioral design pattern, the Observer Pattern. We are going to learn what problem this pattern solves and how we can implement it in C#. To download the source code for this article, you can visit our...

Different Ways to Initialize Arrays in C#

Different Ways to Initialize Arrays in C#

Arrays are data structures that help programmers store multiple values of a specific type in a single variable. We can use different techniques to initialize arrays in C#, and we are going to discuss them in this article. To download the source code...

SortedList in C#

SortedList in C#

A SortedList in C# is a collection of key-value pairs that must be sorted at any given point in time based on its keys. This data structure guarantees that whenever we add or remove elements from any point in the list, the order of the list will remain the same. In...

Visitor Design Pattern in C#

Visitor Design Pattern in C#

The Visitor pattern allows decoupling algorithms from the objects on which they operate. It allows adding and changing functionalities in a type-safe and SOLID manner. This is one of the most complex classic design patterns. In this article, we'll discuss how it's...

How to Find the Maximum Value of an Array in C#

How to Find the Maximum Value of an Array in C#

In this article, we are going to learn different techniques to find the maximum value of an array in C#. At the end of this article, we will do a performance benchmark to check which is the faster approach.  To download the source code for this...

Named Arguments and Optional Parameters in C#

Named Arguments and Optional Parameters in C#

In this article, we are going to learn about the named arguments and optional parameters in C#. More importantly, we are going to see the use cases for both techniques and learn how to use them. To download the source code for this article, you can...

Composition vs Inheritance in C#

Composition vs Inheritance in C#

Composition and Inheritance are programming techniques to establish relationships between different classes. When working with an object-oriented language like C#, it is natural that we come across classes and objects. These classes, more than often, need to interact...

Difference Between DateTime.Now and DateTime.UtcNow in C#

Difference Between DateTime.Now and DateTime.UtcNow in C#

In this article, we’re going to learn about the difference between DateTime.Now and DateTime.UtcNow in C#. Additionally, on a more general level, we're going to learn the difference between formatting DateTime values in local time vs in universal time, and also how to...

DateOnly and TimeOnly in C#

DateOnly and TimeOnly in C#

In this article, we are going to explore DateOnly and TimeOnly in C#, see what functionality exists for both, and help decide when to use one or the other. When it comes to dates and times in C#, for the longest time we have been stuck with the DateTime struct, to...

How to Copy Array Elements to New Array in C#

How to Copy Array Elements to New Array in C#

In this article, we are going to learn how to copy array elements to a new array in C#. We are going to see many different ways to accomplish this task, and at the end, we will do a benchmark to check which is the best way to copy elements from one array to another....

Difference Between ValueTuple and Tuple in C#

Difference Between ValueTuple and Tuple in C#

In this article, we are going to take an in-depth look at the difference between ValueTuple and Tuple. We are also going to look at extra features that came with ValueTuples and also some potential drawbacks. To download the source code for this...

Switch Expression With Multiple Cases With the Same Result in C#

Switch Expression With Multiple Cases With the Same Result in C#

In this article, we are going to learn how to create a switch expression with multiple cases that have the same result. We can combine the cases inside the switch statement either in a relational pattern or a constant pattern. With the relational pattern, we compare...