How To
How to use String.Join() in C#
By Tan Lee Published on Mar 05, 2025 170
You can utilize String.Join() to convert a collection of items into a single string with a specified separator (like a comma).
Default access modifiers in C#
By Tan Lee Published on Mar 05, 2025 133
In C#, classes (and other types) have internal access by default, while class members (methods, properties, fields) are private by default.
internal vs protected in C#
By Tan Lee Published on Mar 05, 2025 119
The access modifiers public and private are straightforward: public means everything has access, while private restricts access solely to the class itself.
Synchronous operations are disallowed
By Tan Lee Published on Mar 04, 2025 153
When performing a synchronous I/O operation in ASP.NET Core (such as writing to a file), you may encounter the following exception:
How to convert hex string to byte array in C#
By Tan Lee Published on Mar 04, 2025 206
You can convert a hex string to a byte array in C# using a lookup table and bitwise operations for efficiency.
How to use enum flags in C#
By Tan Lee Published on Mar 04, 2025 166
Enum flags allow you to store multiple values in a single enum variable or parameter. This is a great alternative to passing multiple boolean values. You set multiple values by using a bitwise OR operation.
How to call a static method using reflection in C#
By Tan Lee Published on Mar 04, 2025 243
To call a static method using reflection in C#, follow these steps:
InvalidArgument=Value of ‘0’ is not valid for ‘SelectedIndex’
By Tan Lee Published on Mar 04, 2025 128
You might encounter the following error when setting the SelectedIndex of a ComboBox:
How to Use string interpolation instead of string.Format in C#
By Tan Lee Published on Mar 04, 2025 162
Using string.Format() can lead to errors and runtime exceptions, making code harder to maintain. String interpolation provides a safer, more readable alternative.
How to Fill a Dropdown with Enum Values in C#
By Tan Lee Published on Mar 04, 2025 179
When you need to display enum values in a dropdown (ComboBox control with DropDownStyle=DropDown), it's best to populate the list dynamically instead of manually adding each value.
Cannot use a lambda expression as an argument to a dynamically dispatched operation
By Tan Lee Published on Mar 04, 2025 100
You may encounter the following compiler error when attempting to use a lambda expression on a dynamic object:
How to consume an SSE endpoint with HttpClient in C#
By Tan Lee Published on Mar 04, 2025 232
You can consume a Server-Sent Events (SSE) endpoint using HttpClient in C# by reading the event stream asynchronously.