0

In this code:

protected static void HandleExceptions(Exception E)
{
    switch (E)
    {
        case MongoWriteException _ :
        {

what does the discarded variable ('_' here) is supposed to be?

Thomas
  • 10,933
  • 14
  • 65
  • 136
  • 1
    Exactly that. Discarded. – RobIII Nov 16 '18 at 13:52
  • It's called pattern matching. See the marked duplicate, it should explain it. In summary `_` gets assigned the cast value of the switch if there is a type match. – Igor Nov 16 '18 at 13:53
  • Just saw, it's a cool feature; so, in the case of the code I posted it's useless then as it's discarded? – Thomas Nov 16 '18 at 13:54
  • If you have no need to use the instance cast as `MongoWriteException` then you can remove `_`. – Igor Nov 16 '18 at 13:56

0 Answers0