From https://blogs.msdn.microsoft.com/dotnet/2017/03/09/new-features-in-c-7-0/:
We allow "discards" as out parameters as well, in the form of a _, to let you ignore out parameters you don’t care about:
p.GetCoordinates(out var x, out _); // I only care about x
Consider the following code:
void Foo(out int i1, out int i2)
{
i1 = 1;
i2 = 2;
}
int _;
Foo(out var _, out _);
Console.WriteLine(_); // outputs 2
Questions:
Why is the "discard" out parameter being outputted in this context?
Also, shouldn't there be an "already defined in scope" error for out var _
?
int i;
Foo(out var i, out i);
Console.WriteLine(i); // Error: A local variable or function named 'i'
// is already defined in this scope