Search⌘ K
AI Features

Working with Spans, Indexes, and Ranges

Explore how to improve memory efficiency and performance in C# by using Span<T> to work with array subsets without duplication. Learn to identify positions with Index and select ranges using Range, enabling optimized data manipulation and extraction in your applications.

One of Microsoft’s goals with .NET Core 2.1 was to improve performance and resource usage. A key .NET feature that enables this is the Span<T> type.

Using memory efficiently using spans

When manipulating arrays, we often create new copies of subsets of existing ones so that we can process just the subset. This is not efficient because duplicate objects must be created in memory. If we need to work with a ...