C# Out Parameter

Why it is necessary for the out parameter to be assigned to before it leaves the current method? Can someone please elaborate me what is going inside the shell? Thanks in advance.

Jon Skeet
people
quotationmark

Why it is necessary for the out parameter to be assigned to before it leaves the current method?

Think of an out parameter as an extra return value. Just as you can't return from a non-void method without specifying the return value, you can't return from a method with an out parameter without setting a value for the parameter.

This in turn allows the argument for an out parameter to be definitely assigned after the method has completed, because it will definitely have been given a value by the method:

int value;
Foo(out value);
Console.WriteLine(value); // This is fine

people

See more on this question at Stackoverflow