Fading Coder

One Final Commit for the Last Sprint

Dynamic Type Instantiation and Runtime Inspection in C#

When building extensible console utilities, hard-coding instantiation logic with switch blocks forces modifications for every new implementation. Consider a scenario requiring dynamic creation of derived types based on user input without recompiling the host application. A base type Organism defines...

Common Pitfalls and Solutions When Using XmlReader and XmlWriter in .NET

When processing XML files larger than 100MB, using XmlDocument to load the entire file into memory becomes inefficient, leading to high memory consumption and long processing times. In such scenarios, switching to XmlReader and XmlWriter for stream-based processing offers significant performance ben...

Overview of C# 6.0 Language Improvements

Inline Property Initializers and Read-Only Auto-Properties Properties can now be initialized directly at their declaration, eliminating the need for a constructor. Additionally, getter-only auto-properties can be assigned during initialization. public class Employee { public int Id { get; set; } = 0...

C# Threading Fundamentals: Mastering System.Threading.Thread

Instantiating and Launching Workers Threads execute concurrently with the main application flow. By default, a newly created thread begins execution immediately upon calling Start(), allowing it to run in parallel with the primary process. using static System.Console; using static System.Threading.T...

Common Pitfall: Why DateTime.Now Returns an Incorrect Past Date

When validating a user's date of birth with FluentValidation, comparing the input against DateTime.Now.Date can produce unexpected results: an error may incorrectly state that the input date (e.g. 2020-07-06) cannot be after the current date, even when the actual current date is 2020-07-08, and the...

Implementing Resilience Patterns in .NET with Polly: Practical Scenarios

using System; namespace ResilienceDemo.Core { public abstract class ResilienceScenario { public abstract string Name { get; } public void Log(string message, ConsoleColor color) { lock (typeof(Console)) { var originalColor = Console.ForegroundColor; Console.ForegroundColor = color; Console.WriteLine...

Practical C# Syntactic Features for Cleaner, More Readable Code

C# syntactic features refer to a set of language capabilities designed to reduce boilerplate code and improve code legibility. All these features are compiled down to lower-level runtime-compatible code during build, while offering far more intuitive and concise syntax for developers. Expression-Bod...

Understanding the Implementation and Mechanics of Tasks in .NET

The System.Threading.Tasks namespace in .NET 4 abstracts thread functionality, utilizing the underlying ThreadPool. A task represents a unit of work that can be executed asynchronously on a separate thread or initiated synchronously, requiring the main thread to wait. Tasks provide an abstraction la...

Training a Custom CNN Image Classifier with TensorFlow.NET in C#

TensorFlow.NET provides a TensorFlow-compatible API for .NET Standard that closely mirrors the Python experience while integrating naturally with the SciSharp stack (NumSharp, SharpCV, Keras.NET, etc.). The example below builds and trains a compact CNN for grayscale image classification entirely in...

Converting MemoryStream Content to and from Strings in .NET

Working with in-memory streams often involves turning byte data into text and vice versa. The key points are: Always use the same text encoding for writing and reading. Reset or manage the Position of the stream before reading. Be careful when disposing StreamReader/StreamWriter; use leaveOpen when...