IAsyncEnumerable with (readonly) ref struct #111579
-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
I'd expect you to get a compilation error with your code; I just tried it and get
|
Beta Was this translation helpful? Give feedback.
I'd expect you to get a compilation error with your code; I just tried it and get
error CS9267: Element type of an iterator may not be a ref struct or a type parameter allowing ref structs
.IAsyncEnumerable<T>
does allow for ref struct Ts, but that doesn't mean async iterators support them, just that it's possible to construct an implementation of the interface that does, in particular whenCurrent
on the enumerator can manufacture the ref struct. The ref struct can't be stored onto a class, so async iterators don't support ref struct Ts... the yielded value is stored on a field on the class.