It matters for two reasons. One is conventional, the other technical.
The conventional reason is that _
conveys active disinterest in the returned value. Sure, you could write var dontcare
instead, but that's just a different arbitrary value.
But as you pointed out, you could also omit the assignment, so it's not just about choosing the shortest name possible. This brings us to the technical reason.
There are cases where you have to declare a parameter and you cannot simply omit it. This applies to out
parameters in method calls, and named tuples when you don't care about all of the tuple's members.
// Out params
if (DateTime.TryParse(dateString, out _))
Console.WriteLine("dateString can be parsed as a DateTime");
// Tuples
var (minimum, _) = FindMinMax(myData);
Console.WriteLine($"The minimum value is {minimum}");
There may be other use cases, these are the two I can think of because I encountered them before.
Is this necessary? Well, it's an easy way to suppress warnings about unused variables. Not all developers care about warnings, but those who do would be pestered by these useless warnings for cases where they are knowingly not using a variable that the compiler forced them to declare anyway.
TheMethodICouldCareLessAboutTheReturnValue(out _)
or (x, _, _) = TheMethodICouldCareLessAboutTheReturnValue
TheMethodICouldntCareLessAboutTheReturnValue
* ;)asdasd
,aaa
,aaaa
, and so on.TheMethodICouldCareLessAboutTheReturnValue
implies some epsilon of caring, so the name is not entirely wrong. MaybeTheMethodICouldBarelyCareLessAboutTheReturnValue
?