How To

How to Get Status Codes with HttpClient in C#
By Tan Lee Published on Mar 06, 2025 730

When using HttpClient to send requests, you can easily access the status code from the HttpResponseMessage object.

How to use TimeZoneInfo in C#
By Tan Lee Published on Mar 06, 2025 807

Time zones can be tricky due to their varying rules and changes, so leveraging a library is a smart approach. In .NET, one such option is the built-in TimeZoneInfo class.

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

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 413

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 510

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 560

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 450

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 501

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 435

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 488

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 494

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 322

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.