How To
Serialize a tuple to JSON in C#
By Tan Lee Published on Feb 05, 2025 457
When you serialize a tuple to JSON, the underlying ValueTuple field names, Item1 and Item2, are used. This is true even if you are using a named tuple. The field names you specify in the tuple declaration won't be reflected in the JSON.
How to check if a nullable bool is true in C#
By Tan Lee Published on Dec 24, 2024 436
In C#, nullable types allow you to represent data that can be absent or undefined, in addition to its usual valid values.
How to get application folder path in C#
By Tan Lee Published on Dec 05, 2024 852
To get the application folder path in a .NET application, you can use the Server.MapPath() method in ASP.NET or AppDomain.CurrentDomain.BaseDirectory for other types of applications.
How to get the current working folder in C#
By Tan Lee Published on Nov 13, 2024 712
In C#, you can get the current working directory using the Directory.GetCurrentDirectory() method, which is part of the System.IO namespace.
Using LINQ to remove elements from a List<T>
By Tan Lee Published on Dec 10, 2024 367
In LINQ, you cannot directly remove elements from a List<T> because LINQ itself is designed primarily for querying and transforming data, not for modifying collections.
Enum Generic Type Constraint in C#
By Tan Lee Published on Feb 04, 2025 374
In this post, let's look at how we can use Enum as a generic type constraint in C#. This feature was introduced in C# 7.3 and allows you to enforce that a type parameter is an enum, providing compile-time safety for your generic methods.
How to use Parallel.For and Parallel.ForEach in C#
By Tan Lee Published on Jan 06, 2025 887
Parallel programming in .NET enables more efficient utilization of system resources and provides greater control over program execution.
How to check if a directory is empty in C#
By Tan Lee Published on Dec 25, 2024 932
In C#, there are a couple of straightforward ways to determine whether a directory is empty.
How to Append a file in C#
By Tan Lee Published on Jun 25, 2024 748
Appending data to a file in C# can be done using various methods provided by the .NET framework.
How to convert string to hex in C#
By Tan Lee Published on Nov 26, 2024 1.44K
To convert a string to its hexadecimal representation in C#, you can use the following method.
How to Convert a string to a double in C#
By Tan Lee Published on Feb 04, 2025 420
There are three common ways to convert a string to a double:
How to get project file path in C#
By Tan Lee Published on Nov 13, 2024 1.99K
In C#, you can get the project file path in different ways.