0
C# passing arguments
In lesson 28.1 it was said that: “There are three ways to pass arguments to a method when the method is called: By value, By reference, and as Output. By value copies the argument's value into the method's formal parameter. Here, we can make changes to the parameter within the method without having any effect on the argument.” But in lesson 37.1 we can change the value of ‘balanced’ variable without using ‘ref’ or ‘out’. Can anyone please explain me why this is working now without ‘ref’ or ‘out’?
4 Respuestas
+ 5
Zoltán The first lesson focuses on the behaviors of input arguments passed into a method. The other is about encapsulation of internal class fields that are accessible by methods of the same class instance.
The method could work with values that are passed in as arguments as well as class fields and other class members.
+ 4
Because it's a member variable (or field). It is accessable from the methods without parameters. ref and out affect only the arguments. Fields are accessable from methods already and thus don't need to be passed. Methods can modify the fields.
+ 1
This could be helpful for you
https://blog.penjee.com/passing-by-value-vs-by-reference-java-graphical/
0
صانكايلاتنرلس