How To
Fixing the Sync over Async Antipattern in C#
By Tan Lee Published on Jan 21, 2025 310
One common mistake developers make is the Sync over Async antipattern, which occurs when blocking waits are used in asynchronous methods instead of awaiting them properly.
C# Add to a Dictionary
By Tan Lee Published on Jan 21, 2025 367
The simplest way to add a key-value pair to a dictionary is by using Dictionary.Add().
How to Modify app.config at Runtime
By Tan Lee Published on Jan 21, 2025 519
When trying to modify the app.config at runtime, it's essential to handle it correctly to avoid errors like:
SqlTypeException: SqlDateTime overflow
By Tan Lee Published on Jan 21, 2025 360
The System.Data.SqlTypes.SqlTypeException: ‘SqlDateTime overflow.' error occurs when you try to insert a DateTime value that is outside the valid range for SQL Server's datetime data type.
SqlTypeException: 'Overflow error converting to data type int.'
By Tan Lee Published on Jan 21, 2025 306
The System.Data.SqlTypes.SqlTypeException: 'Overflow error converting to data type int.' occurs when you try to insert a value that is outside the valid range of the SQL int data type, which is between -2,147,483,648 and 2,147,483,647.
C# Filter a dictionary
By Tan Lee Published on Jan 21, 2025 836
The simplest way to filter a dictionary is by using the LINQ Where() and ToDictionary() methods.
C# Remove items from dictionary
By Tan Lee Published on Jan 21, 2025 494
Dictionaries store key/value pairs. To remove one or more items from a dictionary, you can use the following methods:
C# Get value from dictionary
By Tan Lee Published on Jan 21, 2025 455
Dictionaries store key/value pairs. To retrieve the value associated with a specific key, you can use the indexer syntax by providing the key, like this:
ComboBox with Enum Descriptions
By Tan Lee Published on Jan 21, 2025 318
By default, when you load enum values into a ComboBox, it will display the enum names.
How to use relative paths in a Windows Service
By Tan Lee Published on Jan 21, 2025 221
When using relative paths in a Windows Service, it's important to understand that they are resolved relative to the current working directory.
How to check if another form is open
By Tan Lee Published on Jan 21, 2025 576
When developing a Windows Forms application in C#, you might need to check whether a form is already open.
KeyNotFoundException: The given key was not present in the dictionary
By Tan Lee Published on Jan 21, 2025 450
The KeyNotFoundException occurs when you attempt to retrieve a value from a dictionary using a key that doesn’t exist in the dictionary.