Fading Coder

One Final Commit for the Last Sprint

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...

Understanding the ref and out Keywords for Parameter Passing in C#

In C#, the ref and out keywords are used for parameter passing, enabling a method to modify the values of variables passed to it. However, they follow different rules and are suited for distinct scenarios. ref Keyword ref indicates pass-by-reference. Modifications to the parameter within the method...

Implementing Undo/Redo Functionality with the Generic Stack in C#

The .NET framework includes various generic collections, such as Stack<T> for last-in-first-out operations, Queue<T> for first-in-first-out, List<T> for ordered and indexed elements, LinkedList<T> for doubly linked lists without indexing, and ISet<T> implementations lik...

Building a C# Remote Directory Explorer with Telegram Integration

System Architecture The solution consists of two distinct C# applications: a Controller application running on the local machine, and a Bot agent executing on the remote target machine. The Controller issues commands serialized as JSON, transmits them through the Telegram cloud, and waits for the Bo...

Essential Visual Studio 2022 Extensions for Productivity and Code Quality

C# Method Signature Generation Quickly scaffold method definitions by typing a shortcut keyword followed by the Tab key. method: Standard method imethod: Interface method (lacks implementation body) vmethod: Virtual method smethod: Static method xmethod: Extension method amethod: Asynchronous method...

Streaming Excel Files from ASP.NET to the Client Browser

Directly transmittign an Excel workbook from an ASP.NET backend to a web client involves transforming object collections into tabular data, serializing the output to a memory buffer, and configuring the apropriate HTTP respnose headers. public void ExportCollectionAsExcel<T>(IEnumerable<T&g...

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...

Method Definitions and Usage in C#

A method is a named block of code that encapsulates a set of instructions to perform a specific task. Programs are structured using methods to promote code reuse and organization. Every C# application contains at least one class with a Main method, which serves as the entry point. To utilize a metho...

Leveraging the ThreadPool for Efficient Asynchronous Operations in C#

The ThreadPool provides a managed pool of worker threads, optimizing the execution of numerous short-lived asynchronous operations. Creating a new thread for each brief task incurs significant overhead. The ThreadPool mitigates this by maintaining a reusable collection of threads, assigning queued w...

Implementing and Testing ASP.NET Web API Controllers

Modifying the Web API Route Configuraton By default, ASP.NET Web API uses a routing convention that maps HTTP methods (GET, POST, PUT, DELETE) to controller actions without requiring an explicit action name in the URL. This convention-based routing can become problematic when you need multiple opera...