Pass parameters
In this chapter you will learn:
How Arguments Are Passed
Call-by-value
Copy the value of an argument into the formal parameter. Change made to the parameter have no effect on the argument used in the call.Call-by-reference
A reference to an argument is passed to the parameter. Change made to the parameter will affect the argument used to call the subroutine.
When you pass a value type, such as int or double, to a method, it is passed by value. An object is passed by reference
Parameter modifiers
Parameter modifier Passed by | Variable must be definitely assigned | |
---|---|---|
None | Value | Going in |
ref | Reference | Going in |
out | Reference | Going out |
params
sends in a variable number of arguments as a single logical parameter. Next chapter...
What you will learn in the next chapter:
- Use ref to pass a value type by reference
- Swap two values
- Swap two references
- Change string using ref keyword
Home » C# Tutorial » Class