Math Class in C#
In this article, we are going to describe the Math class in C#. The Math class in C# contains lots of useful static methods for performing all sorts of calculations. We'll briefly describe all the methods in the library with some examples, so it will be quite a long...
Check if DateTime Is Weekend or Weekday
In this article, we are going to find out how to check if a DateTime is a Weekend or a Weekday. Most programming languages work very well with numeric or textual data. But not all of them have the tools for handling information in the form of dates and times. Luckily...
Generate Random Double Numbers in a Range in C#
In this article, we are going to learn how to generate random double numbers in a range in C#. Generate a Pseudorandom Double To generate a pseudorandom double...
Records in C#
In this article, we are going to discuss a new feature added in C#9, called "records". Records offer an alternative to classes and structs and offer a number of advantages over those types that we'll cover in this article. [sc name="github"...
Polymorphism in C#
In this post, we are going to learn about the different types of polymorphism in C#, how they work and how we can use them in our code. Let's start. Types of...
How to Check if .NET Is Already Installed
In this article, we will learn how to check if .NET is already installed on both Windows and Linux. Some developers find it difficult to understand which components of .NET need to be installed before the development starts. This is often the case with beginners....
C# Dictionary: How to Check if a Key Exists
ContainsKey() tells us whether a key is in a dictionary: it takes the key, returns true or false, and costs one hash lookup. If we also want the value, TryGetValue() is the call to reach for. It answers the same question and hands the value back through an out...
Expression-bodied Members in C#
In this article, we are going to learn how expression body definitions and expression-bodied members in C# work. Expression body definitions let us define our methods and properties using a simplified and concise syntax that is extremely readable. We can use...
When to Use Static Classes in C#
C# language supports static classes. In this article, we are going to learn when to use static classes in C# and how to implement them using a .NET (Core) console application. To download the source code for this article, you can visit our GitHub...
Async vs Multithreading in C#: What Is the Difference?
Asynchronous programming is about not holding a thread while waiting. Multithreading is about using more threads to do more work at the same time. They solve different problems and are routinely confused because both are reached for when an application stops...
Creating .NET Project Templates
In this article, we are going to talk about creating .NET Project Templates. Let's get started. What are .NET Project Templates?  We can use .NET Project...
Extended Property Patterns in C#
In this article, we are going to cover a new addition to C# 10, known as extended property patterns. Pattern matching appears to be one of the priorities in the development of C# as a language in the last several years. Every new release adds a few improvements to...
How to Write to a CSV File in C# With CsvHelper
Writing a CSV file in C# takes two objects and one call: a StreamWriter opens the file, a CsvWriter from the CsvHelper package wraps it, and WriteRecords() turns a collection of objects into rows. That is the whole operation for a plain class. Most of this article is...
As and Is Operators in C#
In this article, we are going to learn about the type-testing "as" and "is" operators in C#. Sometimes, when we code in a strongly typed language like C#, the need arises to mix and match a little bit. That's okay, as we can't always foresee the path that the...
How to Generate a Random Number in a Range in C#
To get a random number in a range in C#, we call Random.Shared.Next(min, max). The lower bound is inclusive and the upper bound is exclusive, so Next(1, 7) rolls a die: it returns 1 to 6 and never 7. That exclusive bound is the part worth getting right, so we'll look...
Using Authorization with Swagger in ASP.NET Core
In this article, we are going to look at how to implement swagger authorization in an ASP.Net Core Web API application. We are only going to cover how to set up swagger to accept JSON Web Token (JWT) and how to utilize the token generated to access restricted...
Char Array to String in C#: 3 Ways, Benchmarked
The quickest way to turn a char[] into a string in C# is the string constructor, new string(charArray). string.Concat() and string.Join() give us the same string, but in our .NET 10 benchmark they were several times slower. Let's look at all three, and at why the gap...
Using Autofac in a .NET (Core) Project
In this article, we're going to learn about using Autofac in .NET projects. Autofac is a powerful third-party Dependency Injection (DI) container. Dependency Injection is one of the most important concepts in modern software development since it helps us build loosely...
How to Get an Item by Index From Dictionary in C#
In this article, we’re going to explore accessing Dictionary items by index in C# and its performance considerations. The Dictionary<TKey,TValue> generic class provides the ability to map keys to values. Retrieving a value by using its key is quite fast, almost...
How to Check if StringBuilder Is Empty
In this article, we’re going to talk about the StringBuilder class, and explore options to check if it is empty, directly or indirectly. So, let's start. What...
How to Run Code in a New Thread in C#
In this article, we are going to learn how to run code in another thread in C#. There are many ways to do it in .NET, but we are going to focus on a basic, modern approach. To download the source code for this article, you can visit our GitHub...










