How C# 11 enabled ref fields inside ref struct types:
public ref struct CustomSpanReader<T>
{
private ref T _current; // Ref field pointing directly into stack/heap memory
private int _length;
public CustomSpanReader(Span<T> span)
{
_current = ref MemoryMarshal.GetReference(span);
_length = span.Length;
}
}Allows building custom enumerators, parsing streams, and windowed buffer scanners with direct pointer-like performance while maintaining 100% memory safety.