Skip to content

using + struct indexer emits CS1654, why? #76904

Closed Answered by CyrusNajmabadi
andanteyk asked this question in Q&A
Discussion options

You must be logged in to vote

A using variable is defined to be readonly in the C# language specification. https://github.com/dotnet/csharpstandard/blob/standard-v6/standard/statements.md#1214-the-using-statement

Local variables declared in a resource_acquisition are read-only, and shall include an initializer. A compile-time error occurs if the embedded statement attempts to modify these local variables

Your code is attempting to modify the local variable as we define writing into an indexer on a struct as a mutation of it. If you want the compiler to view things differently, a change would have to happen to the language. Such changes start with a discussion at dotnet/csharplang. Thanks!

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by CyrusNajmabadi
Comment options

You must be logged in to vote
3 replies
@CyrusNajmabadi
Comment options

@andanteyk
Comment options

@CyrusNajmabadi
Comment options

Comment options

You must be logged in to vote
1 reply
@CyrusNajmabadi
Comment options

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