Suppose I write the following code:
int x = 42;
if (x.Equals(x = Foo()))
Console.WriteLine("ok");
Where Foo
is any method returning an integer. Is it guaranteed that the method invocation target (the first x
) is evaluated before it is replaced by the return value of Foo()
? In other words, is this code guaranteed to print ok
if and only if the return value of Foo()
is equal to 42?
I've seen other questions that deal with the order of parameter evaluations, but they don't talk about when the instance (first x
) gets evaluated during runtime for non-static methods -- could someone clarify this for me?