When populating collections in .NET, choosing the right bulk operation improves both clarity and efficiency. Methods like AddRange() and InsertRange() allow multiple items to be added in a single call, reducing overhead compared to repeated individual inserts and clearly expressing intent. When combined with proper capacity planning, these approaches help produce predictable, maintainable code—whether items are being appended or inserted at a specific position.
Tag: Code Performance
Collection Performance: Finding Items at Blazing Speed
Checking whether a collection contains a specific item is a routine task in .NET, and with `Contains()` available on many collection types, it’s easy to assume they all perform similarly. In reality, the underlying data structure and search strategy make a dramatic difference, turning what looks like a simple lookup into a potential performance trap in frequently executed code paths. This article explores how different collections approach item searches, why those differences matter, and how making informed choices can lead to faster, more predictable, and more scalable applications.
String Performance: Why Some String Searches Are Slower Than You Think
String searching is fundamental to modern applications, yet its performance impact is often overlooked. This article explores how common string search patterns can quietly slow down your code—and how small, intentional changes can unlock up to 3× faster execution. Backed by real benchmarks, it shows why paying attention to string search performance matters far more than most developers realize.
Collection Performance: High-Performance Emptiness Checks for Concurrent & Immutable Collections
Count vs IsEmpty can be the difference between fast code and a performance disaster. For some immutable and concurrent collections, the wrong choice is tens of thousands of times slower.
String Performance: Avoid Unnecessary Conversions with StringBuilder
The excerpt from "Rock Your Code" advises caution when using StringBuilder with non-string types, highlighting that unnecessary conversions can hinder performance.
General Performance: Comparing Methods for Retrieving Process File Path
The excerpt from "Rock Your Code" explains two methods for retrieving the initiating file's path in .NET.
General Performance: Exploring Thread ID Retrieval Methods
This article explains two methods to obtain the current thread ID in .NET and shows which method is more performant.
Regular Expression Performance: Supercharge Your Match Counting
String manipulation is crucial in modern applications, significantly impacting performance and memory usage in .NET. learn how to achieve nearly double the speed and zero memory allocations when a count is required from a regular expression.
Microsoft .NET Code Analysis: Efficient String Prefix Checks — StartsWith() vs. IndexOf()
Using IndexOf() for checking if a string starts with a specific value in .NET is inefficient and unclear. This approach performs unnecessary work and obscures intent.
String Performance: The Fastest Way to Get a String’s Length
Retrieving the character count of a string in .NET has various methods: using Span with Length, Length, or Enumerable.Count(). This article will prove which is the fastest method.

You must be logged in to post a comment.