How To

Deserialize JSON to Dynamic Object Using Newtonsoft.Json in C#
By Tan Lee Published on Jan 21, 2025 873

When you need to deserialize JSON without creating multiple classes, you can either deserialize it to a dictionary or to a dynamic object using Newtonsoft.Json.

How to Pass in a Func to override behavior in C#
By Tan Lee Published on Jan 21, 2025 254

In C#, if I want to change the behavior of a method from the outside, I can pass in a function pointer. This technique exists in most programming languages and can be used to implement patterns like the Strategy Pattern.

How to Get a file’s checksum using any hashing algorithm in C#
By Tan Lee Published on Mar 20, 2025 294

This article demonstrates how to calculate a file’s checksum using several hashing algorithms, including MD5, SHA1, SHA256, SHA384, and SHA512.

How to Get a file’s MD5 checksum
By Tan Lee Published on Mar 20, 2025 207

To retrieve a file’s SHA256 checksum, you can use the Get-FileHash cmdlet. This feature has been available since PowerShell v4.

Handle a faulted Task’s exception in C#
By Tan Lee Published on Mar 20, 2025 280

When a Task throws an exception and ceases execution, it becomes "faulted." The key question is: how do you access the exception thrown by a faulted Task?

Serializer options cannot be changed once serialization or deserialization has occurred
By Tan Lee Published on Mar 20, 2025 192

When using System.Text.Json, it’s highly recommended to reuse JsonSerializerOptions objects, as this provides a significant speed boost (up to 200 times faster) for subsequent serialization and deserialization operations.

How to use format strings with string interpolation in C#
By Tan Lee Published on Mar 20, 2025 241

In C#, interpolated strings follow this structure: {variable:format}, where the format part is optional. Normally, the interpolated string would look like this: $"My name is {name}".

How to Query JSON in SQL Server
By Tan Lee Published on Mar 20, 2025 267

Since SQL Server 2016, Microsoft has provided built-in support for managing and querying JSON data. This enables users to store, retrieve, and manipulate JSON documents directly within SQL Server.

How to modify JSON in SQL Server
By Tan Lee Published on Mar 20, 2025 343

In SQL Server, there are a couple of ways to modify JSON data within a table:

How to Check if an IP range is valid in C#
By Tan Lee Published on Mar 20, 2025 291

If you have an IP range defined by a starting and ending IP address (e.g., from user input or a configuration file), you can validate it using the following steps:

Merge two dictionaries in-place in C#
By Tan Lee Published on Mar 20, 2025 262

When merging two dictionaries, you have the option to either perform the merge in-place or create a new dictionary and copy the values over.

Generating XML Documentation and Including It in a NuGet Package in C#
By Tan Lee Published on Mar 20, 2025 328

XML documentation comments in C# serve two main purposes: