News for hackers. Stuff that matters.
Re:A Preview of C# 8 [video] by khaledh on Saturday August 26, 2017 @12:29AM (#15104073)
I know this doesn't solve your problem in C#, but F# gives you a compiler warning in such a case. The following code compiles without warnings or errors:

  type Color = Red | Green | Blue
  
  let superheroFromColor c =
      match c with
      | Red -> "Superman"
      | Green -> "Green Lantern"
      | Blue -> "Spiderman"
However, if you add Yellow as a new case to the Color discriminated union without adding a corresponding match pattern everywhere you match a Color value, you get a compiler warning:

  type Color = Red | Green | Blue | Yellow
  
  ...
  
      match c with
  ----------^
  warning FS0025: Incomplete pattern matches on this expression. For example, the value 'Yellow' may indicate a case not covered by the pattern(s).
Aside: notice how terse and readable the code is compared to the C# equivalent; F# tends to have a high signal-to-noise ratio.

There are no comments on this comment yet.