Controlling How Parameters Are Passed
Learn about C# parameter passing modes: by value, out, and by reference.
We'll cover the following...
We'll cover the following...
When a parameter is passed into a method, it can be passed in one of three ways:
By value (the default): Think of these as in-only.
As an
outparameter: Think of these as being out-only.outparameters cannot have a default value assigned in the parameter declaration and cannot be left uninitialized. They must be set inside the method, or the compiler will give an error.By reference as a
refparameter: Think of these as being in and out. Likeoutparameters,refparameters also cannot have default values, but since they can already be set outside the method, they do not need to be set inside the method. ...