Variables you’ll never use clutter code. Discards (_) explicitly mark them as unused.
Tuple Deconstruction:
// Don't need middle value
var (first, _, last) = ("John", "middle", "Doe");
// Don't need first two
var (_, _, important) = GetThreeValues();
Out Parameters:
// Only care if it parses, not the value
if (int.TryParse(input, out _))
{
Console.WriteLine("Valid number");
}
// Or multiple discards
dict.TryGetValue(key, out _); // Just checking existence
Pattern Matching:
var result = obj switch
{
(string s, _) => s, // Ignore second tuple element
(_, int n) => n.ToString(), // Ignore first element
_ => "Unknown"
};
Standalone Discard:
// Don't care about return value _ = await SomeAsyncMethod(); // Just execute, ignore result
Makes intent explicit – compiler knows it’s intentional!
