out parameter c# code example

Example 1: out parameters c#

int initializeInMethod;
OutArgExample(out initializeInMethod);
Console.WriteLine(initializeInMethod);     // value is now 44

void OutArgExample(out int number)
{
    number = 44;
}

Example 2: c# out argument

// Defining Variable inline
myMethod(out Task output);
output.Start();


// Set existing variable
Task output;
myMethod(out output);
output.Start();

Example 3: passing _ as out variable c#

What is _ in C#?
The underscore character ( _ ) is used to indicate that the parameter 
should be ignored. It's like it is the write-only parameter. 
It's also allowed to discard a variable type. 
Discards could be used to ignore more parameters at once.