ref struct SpanWrapper {
public Span<int> IntSpan;
// Notice the 'scoped' modifier here
public bool LengthMatches(scoped Span<int> s) => IntSpan.Length == s.Length;
}
static void Test() {
Span<int> heapSpan = new[] { 1, 2, 3 };
Span<int> stackSpan = stackalloc[] { 4, 5, 6 };
var wrapper = new SpanWrapper {
IntSpan = heapSpan
};
Console.WriteLine(wrapper.LengthMatches(stackSpan)); // This now compiles!
}