Sign in to track progress and bookmarks.
Modern .NET is fast because of Span. It allows you to look at a piece of data (in a string, an array, or even unmanaged memory) without Copying it. This is the secret to high-throughput parsers and serializers.
When you call `str.Substring(0, 10)`, C# creates a WHOLE NEW string in memory. If you are parsing a 1GB file, you will create 1GB of temporary garbage strings. **Span
Span is a Ref Struct, which means it can ONLY live on the stack. You cannot use it as a field in a class or use it in an `async` method. For those cases, you use **Memory
Q: "How did Span
Architect Answer: "Span allowed the .NET team to rewrite core libraries (like JSON, HTTP, and Kestrel) to use Zero-Allocation patterns. Instead of copying bytes from the network card to an array, and then to a string, and then to a DTO, Span allows us to parse the data directly from the network buffer. This reduced allocations by 90% and is why .NET is now one of the fastest web frameworks in the world."
Quizzes linked to this course—pass to earn certificates.
On this page
1. The Problem with Substring() 2. Ref Struct Constraints 4. Interview Mastery