ref struct SpanWrapper {
public Span<int> IntSpan;
}
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(LengthMatches(ref wrapper, stackSpan)); // Fails to compile here
}
static bool LengthMatches(ref SpanWrapper wrapper, Span<int> comparand) {
return wrapper.IntSpan.Length == comparand.Length;
}