none
C# 8.0 - Pattern Matching in C# 8.0

    General discussion

  • Pattern matching was introduced in C# 7.0 and changed the way we look at identifying the patterns and traits of our types. The changes in C# 8.0 make this even more intuitive and improve both flexibility and readability. How do you apply these new principles and patterns in your code, and what does it mean to introduce things like a switch expression?

    Read this article in the May 2019 issue of MSDN Magazine

    Wednesday, May 1, 2019 5:20 PM
    Owner

All replies

  • The article mentions Haskell, Swift, and other languages that use pattern matching, but then fails to mention the most probable source of C#'s pattern matching inspiration (to this layman)...F#.

    F# is not even mentioned, which would normally be fair for an article about C#. In this case, considering F# is the .NET language that had pattern matching first (and in a more powerful form), giving its 'competitors' Haskell, swift, Kotlin credit for having a feature missing in C# until 7.0 but failing to mention the close cousin that can operate both in object-oriented & functional paradigms is IMO unfortunate.

    Thursday, May 2, 2019 12:38 PM
  • It would be nice to see a comparison code example between C# and F# for pattern matching.
    Thursday, May 2, 2019 4:38 PM
  • See pattern matching for the F# version, and also active patterns to see how F# also allows reusable and parameterised pattern matching. One other difference is that F# allows "closed" type hierarchies (discriminated unions) which allow you to have total matching and not need the use of the "default" catch-all case.


    Friday, May 3, 2019 10:13 AM
  • Microsoft has run out of ideas to improve C# and has been introducing rubbish mathematical expression style syntax in the last few releases. The original version that was a Java clone was so elegant. Soon it will start looking like machine language, regressing back to stone age.
    Saturday, May 11, 2019 1:38 AM
  • Nice, now we have new horrible, ugly and unreadable syntaxis. C# 8.0 with non-nullable reference types and such things like this one, should not be released at all.
    Wednesday, May 29, 2019 11:58 AM