Parameters are defined so that the methods can be made more dynamic. Parameters of a methods can be of 2 types.
- Input parameters.
- Output parameters.
Input parameters are used for bringing values in the method for execution. Whereas output parameters are used for carrying a value ouut of the method after execution of the method
By default every parameter we pass to a method is an input parameter and if we want to define a parameter as output parameter we need to prefix the parameter with ref or out keyword.
public void test (int x,ref int y,out int z)
Here x is an input parameter and y& z are output parameters.
Note: By using return types also we can send results out of a method, but only a single result whereas if we are sending results out of a method using output parameters we have a chance of sending more than 1 result at the time of execution.
No comments:
Post a Comment