c# - When is the variable from the calling scope altered, if using out parameters? -
i cannot try rigth now, sure, knows:
void func(out mytype a) { = new mytype(); // other stuff here // take time ... , return }
when call in asynchronous manner that:
mytype a; func(out a);
will altered immediately, once assigned in function? or new object reference assigned when function returns?
are there specifications if want relay on implemented behavior?
it's assigned once assigned in function. use of out
provides reference whatever passed in, means gets modified whenever modified in method.
an extract c# language spec:
5.1.6 output parameters
a parameter declared out modifier output parameter.
an output parameter not create new storage location. instead, output parameter represents same storage location variable given argument in function member or delegate invocation. thus, value of output parameter same underlying variable.
the following definite assignment rules apply output parameters. note different rules reference parameters described in §5.1.5.
· variable need not assigned before can passed output parameter in function member or delegate invocation.
· following normal completion of function member or delegate invocation, each variable passed output parameter considered assigned in execution path.
· within function member or anonymous function, output parameter considered unassigned.
· every output parameter of function member or anonymous function must assigned (§5.3) before function member or anonymous function returns normally.
within instance constructor of struct type, keyword behaves output parameter of struct type (§7.6.7).
Comments
Post a Comment