How To
Remove non-alphanumeric characters from a string in C#
2/5/2025 9:00:29 AM 133
A simple approach to removing non-alphanumeric characters from a string is by utilizing a regular expression (regex):
Ignore case with string.Contains() in C#
2/5/2025 8:51:57 AM 63
By default, string.Contains() performs a case-sensitive search for a substring (or character) within a string.
Deserialize JSON using different property names in C#
2/5/2025 8:49:43 AM 254
When working with JSON data where property names don’t match your class property names, and you cannot alter the JSON or class structure, you have three main options to handle this discrepancy:
Deserialize JSON to a derived type in C#
2/5/2025 8:43:12 AM 173
To deserialize JSON into a derived type, you typically embed the type name in the JSON string. During deserialization, the system checks the type name against known derived types and deserializes it to the correct type.
Deserialize JSON to a dictionary in C#
2/5/2025 8:28:12 AM 216
To deserialize JSON into a dictionary in C#, you can use the built-in JsonSerializer.Deserialize() method from the System.Text.Json namespace or use JsonConvert.DeserializeObject() from the popular Newtonsoft.Json library.
Deserialize a JSON array to a list in C#
2/5/2025 8:17:09 AM 194
To deserialize a JSON array into a list in C#, you can use the JsonSerializer class from the System.Text.Json namespace.
Serialize a tuple to JSON in C#
2/5/2025 8:08:55 AM 168
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.
Serialize and Deserialize a Multidimensional Array in JSON using C#
2/5/2025 7:51:15 AM 489
By default, System.Text.Json does not support serializing or deserializing multidimensional arrays.
Modifying Date Format for JSON Serialization in C#
2/5/2025 7:42:22 AM 153
When serializing a DateTime object using the System.Text.Json library in C#, the default date format used is the ISO-8601 standard (e.g., 2022-01-31T13:15:05.2151663-05:00).
Serialize anonymous types with System.Text.Json in C#
2/5/2025 7:34:53 AM 158
In C#, you can use the System.Text.Json library to serialize anonymous types by selecting properties from an existing object and serializing them into a JSON string.
Serialize to JSON in Alphabetical Order in C#
2/5/2025 7:24:07 AM 108
There are two ways to serialize an object’s properties to JSON in alphabetical order using System.Text.Json:
Ignore null properties during JSON serialization in C#
2/5/2025 7:16:39 AM 295
By default, null properties are included in JSON serialization.