Quantcast
Channel: Programming
Viewing all articles
Browse latest Browse all 20

C# 7.0 Switch Case (Pattern Matching)

$
0
0
A really cool feature that I've been starting to use more frequently is pattern matching which also is cleanly implemented for switch statements in C#.

Example:
Code:
switch (_commTransport)
{
    case TerminalDebugClient _:
        ((TerminalDebugClient)_commTransport).HostValidation += OnHostValidation;
        break;
    case SshDebugClient _:
        ((SshDebugClient)_commTransport).HostValidation += OnHostValidation;
        break;
}

This allows me to check the type of object...

Read more

Viewing all articles
Browse latest Browse all 20

Trending Articles