3 ms·
Span (safely refers to data anywhere) and Memory (safely refers to data on the heap only) have a much nicer API than arrays. ArraySegment has had a facelift but
by zamalek 8y ago
Span (safely refers to data anywhere) and Memory (safely refers to data on the heap only) have a much nicer API than arrays. ArraySegment has had a facelift but to nit: ArraySegment is a pain to type. Also, unlike arrays, there are read-only variants - which are good for rich type checking. In addition you can easily reinterpret cast between blittable types (the new 'unmanaged' generic constraint) for when you are participating in mortal sins such as directly serializing byte representations.
Tons of reasons to use them besides performance. We use them for those reasons and if there is a performance boon, great bonus!