AceInfinity
Emeritus, Contributor
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:
This allows me to check the type of object described by my interface and also assign it to an identifier if I wanted to process it directly, or just use _ to avoid that. :thumbsup2:
I find this a bit more legible than the if ( is ...) variation when it comes to multiple statements, and definitely more so than the as operator and null check.
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 described by my interface and also assign it to an identifier if I wanted to process it directly, or just use _ to avoid that. :thumbsup2:
I find this a bit more legible than the if ( is ...) variation when it comes to multiple statements, and definitely more so than the as operator and null check.
Last edited: