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
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:
Before calling a method, a: 10
After method called, a: 20