Ref and ref-like parameters of async methods
Specification: proposals/async-method-ref-parameters.md
Discussion: #9997
Summary
This is a follow-up to the C# 13 feature Allow ref and unsafe in iterators and async, extending the relaxation of ref and ref struct variables in async methods to method parameters as well, with the same overall semantics. Under this proposal, ref/in/out parameters or parameters of ref-like types shall be usable in async methods, including local functions and anonymous functions. They shall have the same behavior as locals: they are available up to an await boundary, and require reassignment afterwards to be usable again.
public async ValueTask ReceiveMessageAsync(in Message message)
{
var (sender, recipient) = (message.Sender, message.Recipient);
await LogMessageAsync(sender, recipient);
// do something else with the variables
}
This proposal does not cover iterator methods, since their code always executes lazily.
Design meetings
Ref and ref-like parameters of async methods
Specification: proposals/async-method-ref-parameters.md
Discussion: #9997
Summary
This is a follow-up to the C# 13 feature Allow ref and unsafe in iterators and async, extending the relaxation of
refandref structvariables inasyncmethods to method parameters as well, with the same overall semantics. Under this proposal,ref/in/outparameters or parameters ofref-like types shall be usable inasyncmethods, including local functions and anonymous functions. They shall have the same behavior as locals: they are available up to anawaitboundary, and require reassignment afterwards to be usable again.This proposal does not cover iterator methods, since their code always executes lazily.
Design meetings