Pattern-based using on mutable ref struct doesn't allow the struct to be passed by ref #4345
Replies: 3 comments 5 replies
-
I'm not sure if I understand you correctly, sorry if I don't. |
Beta Was this translation helpful? Give feedback.
-
I have to imagine the rationale here is that developers can see the In fact, if you use legacy There's no way to tell if a struct being passed by ref is merely being mutated or being re-assigned entirely. You'll just have to type out the |
Beta Was this translation helpful? Give feedback.
-
Perhaps C# needs a new mutable pass by ref but disallow re-assign. Something like [Edit] Looks like #7842 had the same idea. |
Beta Was this translation helpful? Give feedback.
-
When trying to convert this into
using
:https://github.com/dotnet/runtime/blob/5aef85ae3da23dfd49f95be1c9336f1bad2e0123/src/libraries/System.Private.CoreLib/src/System/ApplicationId.cs#L38-L72
ValueStringBuilder
must be passed as ref, because it's method may acquire new resource that requires dispose.The assignment protection for using variable is sure for reference types, but not for value types.
Can we modify the rule to allowing
ref
for this case?Beta Was this translation helpful? Give feedback.
All reactions