How To

How to Get key with the max value in a dictionary in C#
By Tan Lee Published on Mar 06, 2025 665

The simplest way to retrieve the key with the maximum value in a dictionary is to use the Linq MaxBy() method (available since .NET 6).

How to use JsonDocument to read JSON in C#
By Tan Lee Published on Mar 06, 2025 318

The JsonDocument class in C# allows you to read and process JSON data efficiently without needing to deserialize the entire JSON into an object.

How to Get and send JSON with HttpClient in C#
By Tan Lee Published on Mar 06, 2025 401

The easiest way to fetch and submit JSON data using HttpClient is through the GetFromJsonAsync() and PostAsJsonAsync() extension methods from the System.Net.Http.Json namespace, as demonstrated below:

How to use JsonExtensionData in C#
By Tan Lee Published on Mar 06, 2025 384

The JsonExtensionData attribute (from System.Text.Json) is useful for deserializing properties that don't match your class structure. Without this attribute, any extra JSON fields will be ignored, leading to null properties in the resulting object.

How to Share a file between multiple projects in Visual Studio
By Tan Lee Published on Mar 06, 2025 330

When you need to share a file across multiple projects without duplicating its contents, you can create a link to the existing file.

How to add .gitignore in Visual Studio
By Tan Lee Published on Mar 06, 2025 353

Adding a .gitignore file to your Git repository is crucial. It specifies which files Git should ignore in your source directory, preventing unnecessary files like build output files from being pushed to the repository.

How to set multiple startup projects in Visual Studio
By Tan Lee Published on Mar 06, 2025 327

Since Visual Studio 2019, you can configure multiple startup projects within the solution properties.

How to Deserialize JSON as a stream in C#
By Tan Lee Published on Mar 06, 2025 386

To deserialize JSON as a stream in C#, you can use either System.Text.Json or Newtonsoft.Json.

How to use JsonNode in C#
By Tan Lee Published on Mar 06, 2025 363

When you want to handle JSON without creating specific classes for (de)serialization, JsonNode offers a flexible alternative.

TimeZoneInfo with current UTC offset in C#
By Tan Lee Published on Mar 06, 2025 243

TimeZoneInfo provides the base UTC offset, which can lead to confusion since the offset may vary depending on the date due to daylight saving time.

How to Parser a CSV file in C#
By Tan Lee Published on Mar 06, 2025 271

Parsing a CSV file in C# can be done in a few different ways depending on your needs.

How to read configuration from appsettings.json in C#
By Tan Lee Published on Mar 06, 2025 505

The appsettings.json file is an efficient way to store and retrieve your application's configuration. It's a JSON file, which makes it much easier to work with than the older XML-based app.config used in earlier versions of .NET.