You have to look at the table of precedence and associativity of operators.
The parentheses used already give a guarantee that everything inside it will be executed before and the result of this whole expression is that it will be used by if
. Therefore
Within this expression all that is on the right side of the =
will be executed first since the association is right to left. Anyway it would also take time to execute the assignment since it has low precedence.
Picking up the expression conta.Saca(Convert.ToDouble(txtValor.Text))
will first execute the .
since he has the highest precedence along with parentheses. He goes first because the associativity is left to right, and he’s more left. The same goes for what is within each parenthesis. Then the execution will be:
temp = txtValor.Text
temp = Convert.ToDouble(temp)
temp = conta.Saca(temp)
retorno = conta.Saca(temp)
if (retorno)
using System;
public class C {
public static int Main() {
var conta = new Conta();
var txtValor = new Form();
bool retorno;
if ((retorno = conta.Saca(Convert.ToDouble(txtValor.Text)))) {
Console.WriteLine(retorno);
return 1;
}
return 0;
}
}
public class Conta {
public bool Saca(double x) => true;
}
public class Form {
public String Text;
}
Behold working in the ideone. And in the .NET Fiddle. Also put on the Github for future reference.
In fact the IL shows this:
IL_000b: ldloc.0 //bool retorno;
IL_000c: ldfld string Form::Text //txtValor.Text
IL_0011: call float64 [mscorlib]System.Convert::ToDouble(string) //Convert.ToDouble(txtValor.Text)
IL_0016: callvirt instance bool Conta::Saca(float64) //conta.Saca(Convert.ToDouble(txtValor.Text))))
IL_001b: dup // Duplicate the value on the top of the stack
IL_001c: stloc.1 //retorno = conta.Saca(Convert.ToDouble(txtValor.Text)))
IL_001d: brfalse.s IL_0027 //if ((retorno = conta.Saca(Convert.ToDouble(txtValor.Text)))) {
Behold complete in Sharplab.
Precedence table:
Category |
Opradores |
Associativity |
Postfix |
() [] -> . ++ - - |
Left to right |
Unary |
+ - ! ~ ++ - - (type)* & sizeof |
Right to left |
Multiplicative |
* / % |
Left to right |
Additive |
+ - |
Left to right |
Shift |
<< >> |
Left to right |
Relational |
< <= > >= |
Left to right |
Equality |
== != |
Left to right |
Bitwise AND |
& |
Left to right |
Bitwise XOR |
^ |
Left to right |
Bitwise OR |
| |
Left to right |
Logical AND |
&& |
Left to right |
Logical OR |
|| |
Left to right |
Conditional |
?: |
Right to left |
Assignment |
= += -= *= /= %=>>= <<= &= ^= |= |
Right to left |
Comma |
, |
Left to right |