The out keyword causes arguments to be passed by reference. This is similar to the ref keyword, except that ref requires that the variable be initialized before being passed. To use an out parameter, both the method definition and the calling method must explicitly use the out keyword.
or
Out signifies a reference parameter. Sometimes methods must return more than one value and not store class state. Out fills these requirements. With it we pass parameters whose changes are realized in their calling methods.
Example:--
using System;
class Program
{
static void Main()
{
bool period;
bool comma;
bool semicolon;
const string value = "has period, comma.";
TestString(value, out period, out comma, out semicolon);
Console.WriteLine(value);
Console.Write("period: ");
Console.WriteLine(period);
Console.Write("comma: ");
Console.WriteLine(comma);
Console.Write("semicolon: ");
Console.WriteLine(semicolon);
}
static void TestString(string value, out bool period, out bool comma, out bool semicolon)
{
period = comma = semicolon = false;
for (int i = 0; i < value.Length; i++)
{
switch (value[i])
{
case '.':
{
period = true;
break;
}
case ',':
{
comma = true;
break;
}
case ';':
{
semicolon = true;
break;
}
}
}
}
}
Output
has period, comma.
period: True
comma: True
semicolon: False