How To

How to Convert string list to float list in C#
By Tan Lee Published on Feb 05, 2025 298

You can convert a list of strings to a list of floating-point numbers using float.Parse() on all the strings.

How to Remove a list of characters from a string in C#
By Tan Lee Published on Feb 05, 2025 272

When you want to remove a list of characters from a string, you can loop through the list and use string.Replace():

How to Check if a string contains any substring from a list in C#
By Tan Lee Published on Feb 05, 2025 883

There are various use cases where you may need to verify whether a string contains any element from a list of substrings.

Find a character in a string in C#
By Tan Lee Published on Feb 05, 2025 214

There are several ways to find a character in a string in C#:

Remove non-alphanumeric characters from a string in C#
By Tan Lee Published on Feb 05, 2025 405

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#
By Tan Lee Published on Feb 05, 2025 172

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#
By Tan Lee Published on Feb 05, 2025 700

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#
By Tan Lee Published on Feb 05, 2025 535

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#
By Tan Lee Published on Feb 05, 2025 656

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#
By Tan Lee Published on Feb 05, 2025 611

To deserialize a JSON array into a list in C#, you can use the JsonSerializer class from the System.Text.Json namespace.

Modifying Date Format for JSON Serialization in C#
By Tan Lee Published on Feb 05, 2025 541

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#
By Tan Lee Published on Feb 05, 2025 385

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.