Deep Dive into the Performance of C# range Expressions

Have you ever wondered what happens behind the scenes when you use range expressions in C#? Range expressions are a convenient way to access a slice of an array or a span, using the syntax data[start..end]. For example, data[..1024] means the first 1024 elements of data, and data[1024..] means the rest of the elements. Let’s take a look at a few examples and run benchmarks. The results might be surprising. ...

July 14, 2023 · 7 min · Michael Pavlovsky