नोट
इस पृष्ठ तक पहुंच के लिए प्राधिकरण की आवश्यकता होती है। आप साइन इन करने या निर्देशिकाएँ बदलने का प्रयास कर सकते हैं।
इस पृष्ठ तक पहुंच के लिए प्राधिकरण की आवश्यकता होती है। आप निर्देशिकाएँ बदलने का प्रयास कर सकते हैं।
Discard - A
The _ character serves as a discard, which is a placeholder for an unused variable.
There are two uses for the discard token:
- To declare an unused variable. A discard can't be read or accessed.
- Unused
outarguments:var r = M(out int _, out var _, out _); - Unused lambda expression parameters:
Action<int> _ => WriteMessage(); - Unused deconstruction arguments:
(int _, var answer) = M();
- Unused
- To match any expression in a discard pattern. You can add a
_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.