Latest Posts On Code Maze

How To Check if a URL Is Valid in C#

How To Check if a URL Is Valid in C#

In the world of web development using .NET, it's crucial to make sure the web addresses (URLs) our application uses are correct and safe. In this article, we will understand the basics of how to check if a URL is valid in C#. We'll include some easy-to-understand code...

Serilog With Microsoft’s ILogger in ASP.NET Core

Serilog With Microsoft’s ILogger in ASP.NET Core

Install Serilog.AspNetCore and register Serilog on the host. Every ILogger<T> the framework already injects then writes through Serilog: no controller changes, no new interface, no Log.Information calls scattered through the code. That is the whole integration,...

How to Get the Number of Weekdays Between Two Dates in C#

How to Get the Number of Weekdays Between Two Dates in C#

Manipulating date and time values is a common programming problem in many applications. Have you ever wondered how we can calculate the number of weekdays between two dates? Knowing how to do this can be crucial in scheduling, project management, or resource...

How to Get the Number of Lines in a Text File in C#

How to Get the Number of Lines in a Text File in C#

In C#, understanding how to count lines in a text file efficiently is a fundamental skill. This seemingly simple task is essential, especially in data manipulation, analysis, or validation scenarios. Whether we are dealing with log files, configuration files, or large...

Parallel.ForEachAsync() and Task.Run() With When.All in C#

Parallel.ForEachAsync() and Task.Run() With When.All in C#

Parallel programming is a common and broad concept in the .NET world. In this article, we compare two well-known methods we use to achieve it when running a repetitive asynchronous task. We take a look at how they behave under the hood and compare the pros and cons of...

Calculate the Difference in Months Between Two Dates in C#

Calculate the Difference in Months Between Two Dates in C#

Calculating the difference in months between two dates is a useful skill for C# developers. Having this knowledge helps us in tasks such as subscription management and tracking course durations. In this article, we learn how to use DateOnly, DateTime, and TimeSpan...

How to Check if a Number Is Positive or Negative in C#

How to Check if a Number Is Positive or Negative in C#

In programming, it is very crucial to figure out whether a number is positive or negative. This article will walk through different ways to do that in C#. We will discuss in detail some of the very common ways to evaluate if a number is positive or negative,...

How to Check if a String Contains Only Letters in C#

How to Check if a String Contains Only Letters in C#

In this article, we'll explore different alternatives to check if a string contains only letters in C#. We will learn the characteristics of each approach, discuss the benefits of each one, and choose the one that best fits each situation. [sc name="github"...

How to Log a Class and Method Names Using Serilog

How to Log a Class and Method Names Using Serilog

Developers must implement an efficient logging system to maintain and troubleshoot applications effectively. One popular logging library that provides powerful logging capabilities is Serilog. In this article, we will talk about how to log class and method names using...

New Features in C# 12

New Features in C# 12

In this article, we will explore new features in C# 12. We will describe primary constructors, collection expressions, inline arrays, and other newly introduced features.  We'll need the latest Visual Studio 2022 or .NET 8 SDK to try each of these new C# 12 features,...

Fluxor for State Management in Blazor

Fluxor for State Management in Blazor

Fluxor is a state management library for Blazor that implements the Flux pattern: the same one-way data flow Redux made popular. State lives in one place, components never write to it directly, and every change happens by dispatching an action that a reducer turns...

Properties vs Fields in C#: What Is the Difference?

Properties vs Fields in C#: What Is the Difference?

A field stores data. A property is a pair of accessor methods we call with field syntax, and that indirection is the entire difference. It is where validation, computation, and change notification live. The rule that follows from it is short: expose properties, keep...

Different Ways to Validate an Uploaded File in ASP.Net Core

Different Ways to Validate an Uploaded File in ASP.Net Core

As developers, we often tend to oversee the security of our applications. Whether the user misclicks on the wrong file or purposely uploads a malicious one, we should always validate the input loaded through our application. In this article, we'll look at a few...

AngleSharp in C#: Parsing and Scraping HTML

AngleSharp in C#: Parsing and Scraping HTML

AngleSharp is the most standards-compliant HTML parser for C#: it parses markup exactly the way a browser does and gives us a real DOM we can query with CSS selectors, traverse, and modify. That makes it the right tool for web scraping and HTML processing where...