-
|
I was studying how C# defines / Microsoft C# compiler implements the evaluation order for public class ReferenceType
{
public int Field;
public int SettableProperty { set { } }
public ref int ByRefProperty { get { return ref Field; } }
public int this[int index] { set { } }
public ref int this[int a, int b] { get { return ref Field; } }
}
ReferenceType o = null;
// "Method" has side effects.
o.Field = Method();
o.SettableProperty = Method();
o.ByRefProperty = Method();
o[Method()] = Method();
o[0, Method()] = Method();Please see the test here on GitHub Gist. Also reference to Raymond Chen's blog on C# evaluation order:
Note that he was talking about a hypothetical situation to justify the left-to-right rule. Imagine my surprise when I found otherwise. (See array indexer at last!) From C# spec 12.23.2 simple assignment and 12.8.7 member access and 15.7 properties...
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
|
That's a wall of text and a half. My understanding is that the spec says that all assignment expressions evaluate RHS side first. |
Beta Was this translation helpful? Give feedback.
-
|
After some more search, it appears this issue has been raised: dotnet/csharpstandard#169 and dotnet/csharpstandard#401. |
Beta Was this translation helpful? Give feedback.
Manually converted to issue dotnet/csharpstandard#1478.