TL;DR


Underscores as discards

discard

unsplash-logoShane Rounce

So if you see code like this:

  var (_, _, _, pop1, _, pop2) = QueryCityDataForYears("New York City", 1960, 2010);

The 1st, 2nd, 3rd & 5th values of the returned tuple; we don't care about. Discards were introduced in c# 7.0

This example is from: https://docs.microsoft.com/en-gb/dotnet/csharp/whats-new/csharp-7?WT.mc_id=ondotnet-c9-cxa#discards

Discard refs:


Underscore as a number separator

discard

unsplash-logoSimon Rae

Or more formally ‘digit separator’… again as of c#7 an underscore can also be used when assigning a numeric value. It is syntactic sugar

  int distanceToMoon = 384_400; // same as int distanceToMoon = 384400

Just makes it easier to read

NB. this represents UK number styling.