The first version of
SafeList tried to address a common problem: inserting and removing elements into a
List<T> while you loop over it. It had a lot of problems though and ended up being pretty much useless. Today’s article presents
SafeList 2.0, a radically-improved version that really solves the problem so you can actually use it as a drop-in replacement for
List<T>. Read on for the details, the source code, and even the unit tests that prove it handles all the nasty corner cases for you!
Posts Tagged list
The first version of
foreach loops are really convenient, but are
for loops faster? It’s a simple question, but one that has really wide implications in almost any codebase. Today’s article tests them out to see which is faster for looping over arrays and
Lists. Read on to see which is quicker!
Contrary to what you may have learned in a data structures class, linked lists are virtually always slower than just using arrays. The same goes for array wrapper classes like
List. Today’s article discusses why this is the case and tests it out with a C# Unity app to make sure that the real world validates the theory.
System.Collections.List<T> is used everywhere in C# code. Except for very special cases, it’s the replacement for arrays, linked lists, queues, and most other one-dimensional data structures. This is because it has all kinds of extra functionality, including the ability to grow in size on-demand. Today’s article wonders about how much performance is lost to gain this convenience and tests the
List<T> class against the lowly C# array:
T. How much performance are you giving up with
List and why is that happening? Read on to find out!
Today’s article shows a class that helps clean up your
foreach loops when you want to call
Remove() on the
List you’re looping over. Normally you’d get an exception, but today’s class works around that problem so your code is less error-prone and easier to read. It also discusses some workarounds you can use even if you don’t use
SafeList. Read on to learn how to make your
foreach loops less error-prone! UPDATE: SafeList 2.0 is out!