I was trying this just the other day in Spectre.Console. I wanted an input prompt that would accept currency values. I started down the path of using a decimal representation (TextPrompt<decimal>). While that mostly worked on the input value, it does not support using negative sign, separators, or decimal places. I wanted to be able … Continue reading Currency Input in Spectre.Console
Month: September 2024
Understanding C# Keywords
In C#, keywords play a crucial role in defining how your code behaves. They help in establishing various programming constructs like classes, methods, variables, and even asynchronous behavior in a structured and precise way. This article will explore some essential C# keywords, providing clarity on their purpose and usage. 1. sealed: Preventing Inheritance The sealed … Continue reading Understanding C# Keywords
Introduction to Immutability with Records in C#
With C# 9.0, Microsoft introduced the record keyword, a powerful new addition that makes it easier to work with immutable data. Records are designed to simplify the creation of classes that are primarily intended to store data, and they offer a more concise and expressive way to model data compared to traditional classes. If you've … Continue reading Introduction to Immutability with Records in C#
Basic C# Immutability with Tuples
In software development, one of the common challenges is returning multiple values from a method. Traditionally, we’ve handled this by using techniques like out parameters, creating custom classes or structs, or working with arrays and lists. However, with the introduction of tuples in C#, particularly since C# 7.0, there's a more elegant and straightforward way … Continue reading Basic C# Immutability with Tuples
Why Should I Care about Mutable vs. Immutable Types
In C#, classes and objects can be categorized as mutable or immutable based on whether their state can be changed after they are created. Understanding the distinction between mutable and immutable types is crucial for designing robust, maintainable, and performant applications. Mutable Classes Mutable classes are those whose state or data can be modified after … Continue reading Why Should I Care about Mutable vs. Immutable Types