InternetException

C#

C# · 1 post (all tags)

Pattern matching

· 103 words · ~1 min read · in .NET, interview

#design patterns #SOLID #C#

Pattern matching is used for: testing expression to check if some value have certain characteristics safer compare because ‘==’ and ‘!=’ can be overloaded Examples: a is int number sequence is IList<T> list switch statement: command switch { Operation.SystemTest => RunDiagnostics(), Operation.Start => StartSystem(), Operation.Stop => StopSystem(), Operation.Reset => ResetToReady(), _ => throw new ArgumentException("Invalid enum value for command", nameof(command)), }; switch with ranges: tempInFahrenheit switch { (> 32) and (< 212) => "liquid", < 32 => "solid", > 212 => "gas", 32 => …

Read the whole thing →