This method is Passing Parameters by Output. Unlike other methods that return only a single value from the method, the Out Parameter can return multiple values from a function.
They are similar to reference type, except the data are transferred out rather than into it. C# provide out
keyword for the out parameter type.
Example: C# Out Parameter
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | using System; namespace Programs { class Swapping { // function (user-defined) public void valueFunc(out int val) { int temp = 20; val = temp; } //main method static void Main(string[] args) { Swapping swapObj = new Swapping(); int a = 10; Console.WriteLine("Before calling a method, a: {0}", a); //calling funciton with out keyword swapObj.valueFunc(out a); Console.WriteLine("After method called, a: {0}", a); } } } |
Output:
1 2 | Before calling a method, a: 10 After method called, a: 20 |