Tip #017
Discards
About this tip
_ ignores tuple elements and out values you don't need and declares no variable. Skip values you don't need by assigning them to the _ discard. It works with tuple deconstruction, out parameters and patterns. It is available since C# 7. The key line is var (_, y) = point in discard.cs. Run it and the output reads How high? 10 high!, False.
Did this tip save you some time? Consider buying me a coffee to fuel the next one.
Buy me a coffee
Railway
Referral
Need somewhere to deploy?
My link gets you $20 in credits.
Claim $20 creditI may earn a commission if you become a customer.
Code
var point = (x: 0, y: 10);
var (_, y) = point;Console.WriteLine($"How high? {y} high!");
var ok = int.TryParse("nope", out _);Console.WriteLine(ok);Output
$ dotnet run discard.csHow high? 10 high!False