Out Parameter Modifier in C# with Example

Out Parameter Modifier in C# with Example
Rating: 5 - 1 Votes

Out Parameter Modifier in C# with Example

Out Parameter Modifier in C# with Example

Out Parameter Modifier in C# with Example

An another parameter modifier is out, which we use when we are expecting more than 1 output from a method.  Normally, a method return only 1 type of value depending upon the return data type like string, int, array etc.  In this case, you can create multiple variables of different data types to store the output values and you can create the method of return type void, which will not return any value.  You must use out keyword in front of data type in the method declaration.  Also, before calling that method, you must use out keyword in front of method arguments which you are going to pass.  Just for info, the variables in the method declaration are known as method parameters and the variables passed to that method are known as method arguments.  A simple example is given below, where we want to obtain addition and multiplication of 2 numbers.

Output:

Addition: 30   Multiplication: 200
Press any key to continue . . .