Replies: 4 comments
-
Why do you need a Point pt = new Point(2, 4);
pt.Offset(2, 2); // self-mutating method
Debug.Assert(pt.X == 4 && pt.Y == 6); Any time you call a struct instance method the |
Beta Was this translation helpful? Give feedback.
-
@HaloFour That's what I thought, but I observed this not being the case when I moved the struct enumerator to a class field. I'll create a code example. |
Beta Was this translation helpful? Give feedback.
-
Was the field |
Beta Was this translation helpful? Give feedback.
-
@HaloFour Yes, that must be what happened. Just tried it both ways. So I don't actually need ref locals for anything yet... I was so happy there for a moment 😜 But my dislike of the inconsistency in |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
The ref returns and locals spec is not linked from https://github.com/dotnet/csharplang/blob/master/Language-Version-History.md#c-70-visual-studio-2017 and I'm failing to find it by searching. Because I can't find that trail, I have no idea if this is a limitation of the spec; it almost seems like a bug in Roslyn.
I expect to be able to write this:
Since I can write this:
(I thought this didn't work because I mistakenly had
enumerator
as a readonly class field, but the point still remains.)The workaround is to stop scoping
en
to the loop:You may dispute the liberties I tend to take with
for
loops, but I could construct a similar example that uses iteration, condition and iterator.The point is that it seems wrong that a valid local declaration statement cannot be used in the
for_initializer
:for_initializer : local_variable_declaration | statement_expression_list ;
https://github.com/dotnet/csharplang/blob/master/spec/statements.md#the-for-statement
Beta Was this translation helpful? Give feedback.
All reactions