...

/

Controlling How Parameters Are Passed

Controlling How Parameters Are Passed

Learn about C# parameter passing modes: by value, out, and by reference.

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 out parameter: Think of these as being out-only. out parameters 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 ref parameter: Think of these as being in and out. Like out parameters, ref parameters 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. ...