This repository provides in-depth examples and explanations of advanced C# concepts. Each folder contains code examples and documentation to help understand different C# features and design patterns. Below is an overview of each concept covered in the repository.
- Mutable Data Class
- Primary Unnamed Constructor Initializer
- Singleton Classes
- ThrowArgumentNullExceptionAttribute
- Immutable Record Class
This section explores the concept of mutable data classes in C#. It demonstrates how to define classes with properties that can be changed after object creation. The provided examples compare a conceptual approach using a hypothetical data
keyword with the current implementation in C#.
- Mutable Properties
- Data-Oriented Design
For more details, refer to the readme.
This section delves into a hypothetical feature in C# called the Primary Unnamed Constructor Initializer, which could streamline object initialization. Although this feature is not part of current C#, the repository provides examples and discusses how similar behavior can be achieved with existing syntax.
- Concise Initialization Syntax
- Improved Readability
For more details, refer to the readme.
This folder covers the Singleton design pattern, which ensures a class has only one instance and provides a global access point to it. It includes both conceptual and practical implementations, demonstrating the use of lazy initialization to achieve thread safety.
- Private Constructor
- Lazy Initialization
For more details, refer to the readme.
This section examines the ThrowArgumentNullExceptionAttribute
, a custom attribute used to automatically throw an ArgumentNullException
if a method's argument is null. This attribute can simplify null-checking code and improve readability.
- Automatic ArgumentNullException
- Simplified Null-Checking
For more details, refer to the readme.
This section explores the concept of immutable record classes in C#. Record classes are a feature introduced in C# 9.0 that provide a concise way to define immutable data objects. This section highlights how to use record classes to create immutable objects with value-based equality.
- Immutable Properties
- Value-Based Equality
- Concise Syntax
For more details, refer to the readme.