Events
17 Mar, 9 pm - 21 Mar, 10 am
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
_
acts as a placeholder for a variableThe _
character serves as a discard, which is a placeholder for an unused variable.
There are two uses for the discard token:
out
arguments: var r = M(out int _, out var _, out _);
Action<int> _ => WriteMessage();
(int _, var answer) = M();
_
pattern to satisfy exhaustiveness requirements.The _
token is a valid identifier in C#. The _
token is interpreted as a discard only when no valid identifier named _
is found in scope.
A discard can't be read as a variable. The compiler reports an error if your code reads a discard. The compiler can avoid allocating the storage for a discard in some situations where that is safe.
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Events
17 Mar, 9 pm - 21 Mar, 10 am
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register now