How To

How to Convert a string to an int in C#
By Tan Lee Published on Feb 04, 2025 192

When working with C#, you'll often need to convert a string into an integer.

How to convert char to int in C#
By Tan Lee Published on Feb 04, 2025 223

onverting a char to an int means obtaining the numeric value that the char represents (e.g., ‘1’ becomes 1). This is different from casting a char to an int, which gives you the char's ASCII or Unicode value (e.g., ‘1’ is 49 in Unicode).

How to get types from assembly in C#
By Tan Lee Published on Feb 04, 2025 416

In C#, you can extract type information from an assembly through a reflection-only load. This process allows you to examine metadata without executing the assembly, which can help avoid runtime errors that typically occur with a fully loaded assembly.

How to Convert a list of strings into a set of enums in C#
By Tan Lee Published on Feb 04, 2025 199

Imagine you have a list of user roles that you read from a configuration file or a database when your application starts. Whenever a user logs in, you want to check if their assigned role is part of the allowed roles list.

How to Get subclass properties with reflection in C#
By Tan Lee Published on Feb 04, 2025 261

When you use reflection to get properties, you can retrieve only the subclass's properties by using BindingFlags.DeclaredOnly (which excludes inherited properties).

How to Check if a property is an enum with reflection in C#
By Tan Lee Published on Feb 04, 2025 247

When working with reflection to inspect a class’s properties, you can use PropertyInfo.PropertyType.IsEnum to determine if the property is an enum type.

How to load assemblies at runtime using Microsoft Extensibility Framework in C#
By Tan Lee Published on Feb 04, 2025 225

The Microsoft Extensibility Framework (MEF) is a powerful tool that allows you to load assemblies dynamically at runtime.

Improving Performance by Reusing JsonSerializerOptions in C#
By Tan Lee Published on Feb 04, 2025 222

When dealing with object serialization in C#, the System.Text.Json library is often used for converting objects to JSON and vice versa.

How to detach entities in Entity Framework Core
By Tan Lee Published on Feb 03, 2025 132

Entity Framework (EF) Core is an open-source, object-relational mapper (ORM) that simplifies data access in your application.

How to Implement IP Whitelists in ASP.NET Core
By Tan Lee Published on Feb 03, 2025 200

When working with applications in ASP.NET Core, there may be scenarios where you want to restrict access to your API or web resources to only a specific set of trusted IP addresses.

How to Use Cancellation Tokens in ASP.NET Core
By Tan Lee Published on Feb 03, 2025 281

ASP.NET Core 7, the latest version of Microsoft's open-source web application framework, brings many advanced features from previous .NET versions, one of which is cancellation tokens.

How to Use Simple Injector in ASP.NET Core
By Tan Lee Published on Feb 03, 2025 172

Dependency Injection (DI) is a design pattern where an object receives the dependencies it requires rather than creating them directly.