How To

Sorting a SortedList in Descending Order in C#
By Tan Lee Published on Feb 07, 2025 169

In C#, the SortedList<TKey, TValue> class stores key-value pairs in ascending order of the key by default. If you need to store the elements in descending order, you can achieve this by using a custom comparer.

Difference between delegate and event in C#
By Tan Lee Published on Feb 07, 2025 208

In C#, both delegates and events are essential constructs for handling method references and providing a way to notify subscribers when something happens.

How to calculate code execution time in C#
By Tan Lee Published on Feb 07, 2025 296

To calculate the code execution time in C#, you can use the Stopwatch class from the System.Diagnostics namespace.

How to Read a File Using StreamReader in C#
By Tan Lee Published on Feb 07, 2025 217

To read a file in C#, you can use the StreamReader class. It simplifies reading text from a file by providing various methods for reading data.

Difference Between Hashtable and Dictionary in C#
By Tan Lee Published on Feb 07, 2025 169

In C#, both Hashtables and Dictionaries are popular collections used for storing and retrieving key-value pairs.

Difference between Array and ArrayList in C#
By Tan Lee Published on Feb 07, 2025 133

In C#, both Array and ArrayList are used to store collections of elements.

Writing Text to a Physical File Using StreamWriter in C#
By Tan Lee Published on Feb 07, 2025 143

To write text to a physical file using StreamWriter in C#, you can follow these steps.

Difference between string and StringBuilder in C#
By Tan Lee Published on Feb 07, 2025 161

In C#, both string and StringBuilder are used to work with text, but they differ significantly in how they handle memory and performance when modifying text.

DateTime formats in C#
By Tan Lee Published on Feb 07, 2025 146

In C#, you can convert a `DateTime` object to a string in various formats using the `ToString()` method. By passing the desired format as a string parameter to the `ToString()` method, you can retrieve the date and time in the required format.

How to get unix timestamp in C#
By Tan Lee Published on Jul 11, 2024 2.14K

In C#, you can get the Unix timestamp, which represents the number of seconds that have elapsed since January 1, 1970 (Unix epoch), in a couple of ways.

How to make concurrent requests with HttpClient in C#
By Tan Lee Published on Jan 21, 2025 716

The HttpClient class is designed for making concurrent requests. It is thread-safe, meaning you can send multiple requests at the same time, whether from a single thread or multiple threads.

How to fix 'Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on'
By Tan Lee Published on Jul 08, 2024 1.65K

The error "Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on" typically occurs in multi-threaded applications when you try to update or interact with UI controls from a thread other than the one that created those controls.