Where the return value is returned, for example. calling the go method if it is not populated with the declared variable of the expected type?

We are not forced to fill in the return value, for example. calling the method in the declared variable of the expected type, but what happens to it in this situation?

Where is the next return value returned / What happens to it :?

decimal d = 5.5m; Math.Round(d, MidpointRounding.AwayFromZero); 

Obviously, if I wanted to see the result of a method call, I would do the following:

 decimal d = 5.5m; decimal d2 = Math.Round(d, MidpointRounding.AwayFromZero); // Returns 6 into // the variable "d2" 

(This question does NOT apply to value types, but also refers to link types)

+6
source share
2 answers

It appears from the execution stack :

 IL_000A: call System.Math.Round IL_000F: pop 

If it is a reference type, the link will be pushed out of the stack, and the object itself will eventually be compiled by GC (provided that it has no other links).

+8
source

The return value of the method clicked on caller stack . Whether it will be used or not is a caller code question.

EDIT

Example:

 void Main() { var result = MyCoolFunc(10, 20); {1} } int MyCoolFunc(int prm1, int prm2) { return (prm1 + prm2); } 

Pesudo example of some virtual machine, skipping internal code

 VM_PUSH 10 //prm1 stack state is {10} VM_PUSH 20 //prm1 stack state is {10,20} VM_EXEC MyCoolFunc //call function which executes what need, removes from stack those 2 values and pushes result of the function execution. stack state is {30} 

if we don’t write var result on the line {1}, it ends here, if yes there should be something like this

 VM_ALLOC result //allocate space for result VM_GETFROMSTACK // get content of the stack to result 

VM code is PSEUDO CODE and does not exist in real life. It was used only as an example.

+1
source

Source: https://habr.com/ru/post/905202/


All Articles