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 …

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 …

Events and Delegates in C#

Events and Delegates are two topics in the .NET Framework that are truly misunderstood and many times not understood at all. This post will attempt to explain what events are, how they are related to delegates, and how to use them in your code. What Are Events? Events are a way for objects in the .NET Framework or your own …

Getting Started with AutoMapper

If you are an experienced software developer you have no doubt written thousands of lines of code mapping properties of one object to properties of another object. This is commonly done when creating ViewModel objects or data transfer objects (DTOs). AutoMapper gives you a reusable, elegant solution to this problem. In this post, we will explore how AutoMapper does this. …