String Performance: Formatting

This article discusses the performance differences using string.Format() and interpolation and stresses the importance of using globalization with any string shown to the user. Updated January 2023.

Collection Performance: A Comprehensive Benchmark Analysis of Collection Types in .NET Beyond Arrays and Lists

This article conducts a comprehensive benchmark analysis of various collection types in .NET beyond arrays and lists. It explores the performance of iteration methods, revealing significant differences among types, providing valuable insights for developers to choose the most performant collection type based on their code requirements.

Collection Performance: Adding Items to a Collection

The most popular way to add an item to a collection is by using Add(). The other way is by using Insert() or Prepend(). This article shows performance results for these three methods.

Everything That Every .NET Developer Needs to Know About Disposable Types: Part  2 – Properly Implementing the IDisposable Interface

The second part of this article series focuses on the proper implementation of the IDisposable interface for types in .NET that require memory management. It emphasizes the importance of preventing virtual memory leaks and provides a step-by-step guide to implement the IDisposable pattern correctly, including an example template for ease of use. The article also addresses the implementation of IDisposable in types that inherit from other disposable types.

Collection Performance: Looping Over Reference Type vs. Value Type

Since most of the types and collections I create are typically business objects, I wondered if collections of simpler types would be faster. I decided to benchmark the difference between a List (reference type) with a List (value type).

Collection Performance: Sorting the Record Type

This article shows the difference between sorting a normal class type with a record class type.

Collection Performance: Sorting Collections

There are several ways to sort a collection in .NET. Some of the sorting methods are part of LINQ. Let’s look at the methods that are part of the System.Collections.Generic namespace.

Collection Performance: Looping Over Other Collection Types

This article shows benchmark results for adding items to a List collection by using AddRange() and for().

Collection Performance: Efficiently Checking for Items in a Collection

Before processing collections, always perform null and item checks. For counting items, prefer Count for speed, as it's more efficient than LongCount() and TryGetNonEnumeratedCount(). When working with arrays, use Length or LongLength instead of Count. Benchmarking is crucial for optimizing collection methods in .NET applications.

Collection Performance: Creating New Sorted Collection From a Collection

This article talks about sorting collections with LINQ and doing the same using one of the sorted collections.