As
you would hope, the values of x and y remain identical before and after the call to Add(), as
shown in Figure 4-1.
Figure 4-1.
By default, parameters are passed by value.
The out Modifier
Next, we have the use of output parameters. Methods that have been defined to take output param-
eters (via the out keyword) are under obligation to assign them to an appropriate value before
exiting the method in question (if you fail to do so, you will receive compiler errors).
To illustrate, here is an alternative version of the Add() method that returns the sum of two
integers using the C# out modifier (note the physical return value of this method is now void):
Do'stlaringiz bilan baham: