C# – Use records as a shortcut for defining DTOs

You can declare a record with a single line of code: Note: This feature was added in .NET 5 / C# 9. Records are basically classes (reference types) that work very well as simple data containers (i.e. DTOs). Here’s an example of using a record: This outputs the following: As shown, when you declare a … Read more

C# – Get the last day of the month

The last day of the month is the number of days in that month. To get the number of days in a month, use DateTime.DaysInMonth(year, month): This outputs the following: Notice that it handles leap years (2024) appropriately. Using the number of days in the month, you can get the last day of the month: … Read more

C# – Working with tuples

Here’s how you create a tuple: Tuples are containers for two or more variables. Without tuples, you’d have to use a class/struct, like this: In other words, tuples provide a convenient alternative to class/structs. Instead of having tons of data container classes, you can use tuples. In this article, I’ll show examples of how to … Read more