Skip to content

Instantly share code, notes, and snippets.

@MadsTorgersen
Created March 9, 2017 20:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MadsTorgersen/f6c61b60a81b872140e6f4d7ca7de377 to your computer and use it in GitHub Desktop.
Save MadsTorgersen/f6c61b60a81b872140e6f4d7ca7de377 to your computer and use it in GitHub Desktop.
p.GetCoordinates(out var x, out _); // I only care about x
@abelenky
Copy link

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
Copy link

sean3d commented Mar 13, 2017

I also had the same thought, @abelenky.

@mottykohn
Copy link

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

@elijah-ezaga
Copy link

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