Shallow Copying vs Deep Copying in C#

In this article, I will show examples of shallow copying and deep copying in C#, we can examine the differences, and I will give you a few pointers. Shallow Copying and Deep Copying Shallow copying isn’t a new concept to most programmers. We do it all the time. Reference types (objects) are just a reference to a value on the …

Extension Methods 101

Extension methods have been available in the .NET Framework since 3.0. If you haven’t created one before, the chances are very high that you have at least used one, possibly without realizing it. In this post, we will explore what extension methods are, how to create them, and compare them to regular class methods. What are Extension Methods? Extension methods …

An Introduction to Structs in C#

A struct is a value type that is often used to house a group of related variables, such as the points of a rectangle, together. Structs share many characteristics with classes but they are, at the same time, very different. In this post, we will explore those commonalities and differences and explore some use cases for a struct. What is …

Constructor Chaining in C#

In this post, we will look at constructor chaining in C#. What is Constructor Chaining? Constructor chaining occurs when you use one constructor in a class to call another constructor on the same class. Often, because the constructors must have different signatures, you supply a safe or default value for the second constructor. Listing 1.1 – Constructor Chaining public MessagePrinter(string …

Using the yield keyword in C#

The yield contextual keyword was first introduced in C# 2.0 and despite that fact, it is rarely used. Perhaps it is not a well-known feature or perhaps it is misunderstood but it has plenty of uses. In this post, I will demonstrate how to use the yield contextual keyword and discuss some common scenarios where it would be useful. What does …

Working With Optional Arguments in C#

Optional arguments were introduced in C# 4. They are valid for constructors, indexers, methods, and delegates. In this post, I will cover the basic information needed to use them correctly. What are Optional Arguments? Optional arguments are exactly what they sound like: arguments that you are not required to supply because they have a default value already specified. If no …

Working with Nullable Types in C#

Nullable types were a great addition to C#. They were added way back in C# 2.0 but there is still confusion on how to work with them for some developers, especially junior developers. In this post, I will provide an overview of the most efficient ways to work with them and use them correctly. What are Nullable Types? Nullable types …

A Brief Introduction to ASP.NET Core Middleware

One of the many changes that came with ASP.NET Core is a completely new model for the request pipeline. It is great, though, because it allows complete customization of how requests are handled in your application and there is an out-of-the-box solution for basic applications. Simple needs are serviced if the requirements are simple and the pipeline can be as …