C# – How to use SortedSet

When you have a collection of elements that you’re continuing to add to, and need to keep the objects in sorted order at all times, you can use SortedSet. Internally, it uses a tree data structure to keep elements in sorted order (O(log n) insertion). This is far more efficient than repeatedly sorting a list … Read more

Logging to the database with ASP.NET Core

I was reading about logging in ASP.NET when I came across this statement about logging to the database: When logging to SQL Server, don’t do so directly. Instead, add log messages to an in-memory queue and have a background worker dequeue and insert data to SQL Server. Paraphrased from Microsoft – No asynchronous logger methods … Read more

C# – Set operations with Linq

In this article, I’ll explain four set operations – intersection, union, difference, and symmetric difference – and how to perform these operations using Linq methods (such as Intersect()). These methods work on any type that implements IEnumerable – such as lists, arrays, and sets. Set intersection with Intersect() The intersection of set A {1,2} and … Read more

C# – Parse a comma-separated string from app.config

I’ll show how to parse comma-separated integer values from app.config and load them into a HashSet for efficient lookups. First, take a look at the setting (retryStatusCodes) in app.config: To load and parse this setting from app.config, do the following: The following code shows how to do this: Note: You have to add a reference … Read more