Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardC#ref struct and ref returnsSingle-choice MCQ

Why does the following not compile, illustrating a core rule that makes `ref struct` safe?

ref struct Span2<T> { /* holds a ref/Span<T> */ } class Holder { Span2<int> _field; // <-- error here } static async Task M() { Span2<int> s = default; await Task.Yield(); UseLater(s); // and this is also illegal }