Skip to content

IAsyncEnumerable with (readonly) ref struct #111579

Closed Answered by stephentoub
DemoBytom asked this question in Q&A
Discussion options

You must be logged in to vote

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 when Current 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.

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@huoyaoyuan
Comment options

@colejohnson66
Comment options

@stephentoub
Comment options

@colejohnson66
Comment options

@DemoBytom
Comment options

Answer selected by DemoBytom
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants