Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
p.GetCoordinates(out var x, out _); // I only care about x
@abelenky

This comment has been minimized.

Copy link

commented Mar 10, 2017

I'm under the impression that _ is a valid variable name by itself, which would make this code ambiguous:

int _;                                  // Funny name, but valid. Variable is uninitialized.
p.GetCoordinates(out var x, out _);     // Variable x is declared here.  Is the second param ignored? or is variable `_` used as an out-param?
WriteLine($"Got Coords {x} and {_}");   // Ambiguous: is _ still uninitialized? or was the value set by previous line?

See : https://msdn.microsoft.com/en-us/library/gg615485%28v=vs.88%29.aspx#Variables The section on "Variable Naming"

@sean3d

This comment has been minimized.

Copy link

commented Mar 13, 2017

I also had the same thought, @abelenky.

@mottykohn

This comment has been minimized.

Copy link

commented May 5, 2017

If _ was declared. It works like pre C# 7.0.

@elijah-ezaga

This comment has been minimized.

Copy link

commented Jun 28, 2019

The _ is a discard in C# 7.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.