The evolution of Pattern Matching in C# (from version 6 to 10)

Sdílet
Vložit
  • čas přidán 19. 06. 2024
  • Check out our open positions at Checkout.com here: bit.ly/NickChapsas02
    Join me and let's build the future of payments!
    Check out my courses: dometrain.com
    Become a Patreon and get source code access: / nickchapsas
    This video is sponsored by Checkout.com
    Hello everybody I'm Nick and in this video I will show you how pattern matching was introduced in C# and how it has evolved from version 6 all the way to version 10. It is an amazing feature which can be really handy to prevent you having to write lengthy complicated clauses.
    Timestamps
    Intro - 0:00
    I am hiring! - 0:47
    C# 6 - 1:37
    C# 7 - 3:03
    C# 8 - 5:36
    C# 9 - 9:31
    C# 10 - 13:58
    Don't forget to comment, like and subscribe :)
    Social Media:
    Follow me on GitHub: bit.ly/ChapsasGitHub
    Follow me on Twitter: bit.ly/ChapsasTwitter
    Connect on LinkedIn: bit.ly/ChapsasLinkedIn
    Keep coding merch: keepcoding.shop
    #csharp #dotnet

Komentáře • 158

  • @nickchapsas
    @nickchapsas  Před 2 lety +11

    Check out our open positions at Checkout (dot) com here: bit.ly/NickChapsas02
    Join me and let's build the future of payments!

    • @michaelganzer3684
      @michaelganzer3684 Před 2 lety +1

      Applied and really looking forward to multiplying each others' understanding. My personal goal is no less than improving humanity in itself. :)

  • @kblyr
    @kblyr Před 2 lety +35

    It is becoming really hard to try other languages when your first and favorite language is giving you these awesome features. And .NET is in everything in everywhere.. Thank you Nick for showing this awesome feature

  • @petrusion2827
    @petrusion2827 Před 2 lety +61

    IMHO:
    One thing that would definitely improve pattern matching is to *allow us to use other values besides constants.* As it stands, pattern matching literally forces us to use hard coded magic numbers if we want to do anything more than check types. The biggest reason I'm not using pattern matching as much as I'd love to is because way more often than not I need to match against VARIABLES, not constants. Right now you can't even do a switch expression on a Type object for crying out loud.
    I know that one argument against matching against variables is that then the compiler wouldn't be able to (attempt to) guarantee static analysis, but I don't see a problem in not having it when using variables.
    Seriously, variables in pattern matching have got to be the next step if people are to use it more.
    Even in the context of something similar to the example, if you're branching based on some shape's geometrical properties in a real application, then you're gonna use, say, a float you got as a method argument, not magic numbers.

    • @20windfisch11
      @20windfisch11 Před 2 lety +6

      Even the functional languages where this originated from don’t support this. In F# you also have to do
      match foo with
      | { bar = quux } when quux = baz -> // do stuff
      Same for Scala:
      foo match {
      case Bar(quux) if quux == bletch => // do stuff
      }
      This effectively does what you want, but this is effectively syntactic sugar for an “if”. And this also works in C# using “when”.
      The argument against directly matching against variables is a very valid one, because a defensive style is the way to go today, even in primarily object-oriented languages, which also means everything should be considered immutable by default even if it is not in C#. I miss something like “readonly var a = 42;” - why is this possible for fields but not for local variables?
      You have to adapt your coding style but immutability by default prevents some potentially nasty bugs.

    • @petrusion2827
      @petrusion2827 Před 2 lety

      @@20windfisch11 I don't think I quite understand what you mean. Could you please elaborate? I don't see the connection between immutability and being able to only use magic numbers while pattern matching objects.

    • @willinton06
      @willinton06 Před 2 lety +2

      @@petrusion2827 the relationship goes down to the compiler, in order to make sense of it and optimize it properly the values need to be readonly at compile time, so basically, constant

    • @Eckster
      @Eckster Před 2 lety

      Elixir offers pattern matching like this, it also offers destructuring into new variables using pattern matching. You can also do function overloading using pattern matching.
      However, it's not a strongly typed language, so that may be where the difference lies.

    • @Ruhrpottpatriot
      @Ruhrpottpatriot Před 2 lety +1

      @@20windfisch11 I don't think this is even possible in statically typed languages (without it being syntactic sugar for an if/else). In Rust, i.e. a language with very strong guarantees) you can do this:
      let num = Some(50);
      let y = 10;
      match num {
      Some(x) if x < y => println!("less than {}: {}", y, x),
      Some(x) => println!("{}", x),
      None => (),
      }
      But again: This is syntactic sugar.
      Even in Haskell, which is probably one of the more pure languages you can't do it and have to fall back to input guards, i.e.:
      one = 1 :: Int
      two = 2 :: Int
      foo x
      | x == one = True
      | x == two = False

  • @user-nw8oi9vn9y
    @user-nw8oi9vn9y Před 3 měsíci

    Boom! This blew my mind - loved this video. Please do more "evolution of ..." types of videos please. It really helps me understand what the new features are trying to accomplish.

  • @user-eq4nl1yd3k
    @user-eq4nl1yd3k Před 2 lety +25

    12:36 I think adding parenthesis is also good to make it clear: c is (>= 'a' and = 'A' and

  • @joseluisdeoliveirasantos9131

    I'm not saying it's crazy. But, well, it is crazy! Amazing evolution! Thank you for share that, really a very nice job, another usefull tip, as always!

  • @KentBrakewell
    @KentBrakewell Před 2 lety +2

    When I moved from VB6 to C# 15 years ago, I was shocked at how limited switch case was vs Select Case in the obsolete VB and VBA languages. Now C# has FINALLY surpassed Visual Basic in functionality and even readability with that extremely short syntax. Totally awesome, thank you for waking me up to this new future set!

  • @qtxsystems
    @qtxsystems Před 2 lety

    Nick, excellent work. You really distilled pattern matching down into the most concise example I have seen to date. Very well explained and even taught me something new. Bravo!

  • @mheys1
    @mheys1 Před 2 lety

    I've watched a few of your videos before but this is the one that made me realise I need to subscribe, also going to recommend your channel to my colleagues.

  • @expertreviews1112
    @expertreviews1112 Před 2 lety +1

    Oh man can’t tell you how much I enjoy ur videos… ur the best tech content creator period…

  • @keithwilliamson8428
    @keithwilliamson8428 Před 2 lety +2

    I really appreciate you doing these videos. You're making us better coders 😀

  • @JKhalaf
    @JKhalaf Před 2 lety

    I've recently stumbled upon your channel and so far I love it! Keep up the good work ♥

  • @coderbdev
    @coderbdev Před 2 lety +1

    This is definitely useful for me.
    I learn something from every video. Thanks for the great stuff you put up.

  • @PetroliasChristopher
    @PetroliasChristopher Před 2 lety

    Είσαι τρομερός! great to see people like you sharing such valuable knowledge, keep up the good work!

  • @ehvlullo
    @ehvlullo Před 2 lety +15

    Switch expressions with tuples under the right circumstances can make for crazy improvements to readability and conciseness. Awesome video.

    • @ChaseFreedomMusician
      @ChaseFreedomMusician Před 2 lety +9

      And in the wrong circumstances will make your code a nightmare hellscape of fragmented incomplete edge cases

  • @UnUnkn0w
    @UnUnkn0w Před 2 lety

    Value content! Thanks Nick Chapsas

  • @andreaskarz
    @andreaskarz Před rokem

    Wow, that's amazing - thank you so much

  • @nandkishorsonwale69
    @nandkishorsonwale69 Před 2 lety

    Great explanation of Pattern matching. Thank you.

  • @rajm1976
    @rajm1976 Před 2 lety +18

    I've recently discovered the power of pattern matching when dealing with the returns of delegate functions. A delegate return could be void, an object, Task or Task. Using pattern matching I could determine if I could execute the task and return a result or just await it.
    if (task is Task taskVoid) await taskVoid;
    if (task is Task taskT) result = await taskT;

    • @SebGruch
      @SebGruch Před 2 lety +2

      Perhaps Either would be better in this scenario?

    • @rajm1976
      @rajm1976 Před 2 lety

      @@SebGruch No, I know there is only a single return type as I defined the delegate. Plus I have a single function to execute the delegate which doesn't know about what it will be returning at he point it is invoked.

    • @willinton06
      @willinton06 Před 2 lety

      @@SebGruch yeah this sounds like very bad design, not your Either, that one is cool, but the multi type return

  • @faridfereidoony227
    @faridfereidoony227 Před 2 lety

    Great video with awesome explanation!

  • @tinkerfu7350
    @tinkerfu7350 Před 2 lety

    So nice, today I learned new stuff. Thanks

  • @oleglivcha5041
    @oleglivcha5041 Před 2 lety

    Great video,thank you very much!

  • @RobinHood70
    @RobinHood70 Před 2 lety +16

    2:05 Wait, there are example numbers besides 69 and 420? Who knew? 😛

  • @sindiinbonnienclyde
    @sindiinbonnienclyde Před 2 lety

    Great channel, great video and great examples 👌🏾

  • @XpLoeRe
    @XpLoeRe Před 2 lety

    Thanks dude! Awesome.

  • @leonid2663
    @leonid2663 Před 2 lety

    Great job!

  • @LeeRoyAshworth
    @LeeRoyAshworth Před 2 lety

    Very nice examples and explanation 👍

  • @bartblommerde550
    @bartblommerde550 Před 2 lety +2

    Great summary of a feature I have not be using a lot, since in "oldskool software engineering" dynamic type checking is considered to be a bit of a code smell. But still, I can see the benefits of this "pattern matching", although the name is really confusing to me : I consider this to be "dynamic type matching", and e.g. regular expression matching is what I call "pattern matching".

  • @najibmestaoui6950
    @najibmestaoui6950 Před 2 lety

    My passion of c# is increasing thanks to your videos Nick 😉

  • @georgekalokyris
    @georgekalokyris Před 2 lety

    Well said - thanks Nick!

  • @danielm5710
    @danielm5710 Před 2 lety

    Very nice! Though I was up to date. Was wrong :) learned something new. Thanks!

  • @mos90
    @mos90 Před 2 lety

    amazing. thanks

  • @SJA-mh2uz
    @SJA-mh2uz Před 2 lety

    you do a good job. thank you

  • @turbosega
    @turbosega Před 2 lety

    Really nice feature!

  • @sunilanthony17
    @sunilanthony17 Před 2 lety

    Love it, some good stuff there.

  • @masifakbar
    @masifakbar Před 2 lety

    Good explanation

  • @CodeWithAnup
    @CodeWithAnup Před 2 lety

    This is why I fall in love with C#

  • @mrwalkan
    @mrwalkan Před rokem

    this is so good.

  • @tuberklz
    @tuberklz Před 2 lety

    i love how changes makes c# more expressive.

  • @timnguyen8190
    @timnguyen8190 Před 2 lety

    Usually, great content!

  • @manggexie1241
    @manggexie1241 Před 2 lety

    This is so cool

  • @COLEplusTEN
    @COLEplusTEN Před 2 lety +1

    Damn this is beautiful.

  • @UnBayleefable
    @UnBayleefable Před 2 lety

    Oh lord this is going to make my code reviews look much cleaner at the very least

  • @diego_samano
    @diego_samano Před 2 lety

    Fantastic video as always!
    No open positions for Mexico, really sorry about that ☹ maybe one day...

  • @DickBakerSql
    @DickBakerSql Před 2 lety +6

    at offset 12:40 important to note that "and pattern combinator has higher precedence than or" otherwise reader is left wondering if code is correct. Personally I prefer to explicitly include parens here to be 110% clear!

  • @warrenbuckley3267
    @warrenbuckley3267 Před 2 lety

    What interesting shape sizes you have there.

  • @CRBarchager
    @CRBarchager Před 2 lety

    0:47 Sadly you're not hiring in Denmark. - Very good video as always. Thank you for sharing!

  • @manuillo94
    @manuillo94 Před 2 lety +19

    Really wish pattern matching could accept non-constant values. Can't use it almost anywhere because of that.

    • @babri1402
      @babri1402 Před 2 lety +7

      This so much. In a lot of real life projects, you are getting configurations from database instead of hardcoding them. So for instance in the pricing example shown, those discounts criteria range could partially be coming from db & then pattern matching won't accept it.

  • @zoran123456
    @zoran123456 Před 2 lety +1

    Ok, this really affects you if you are focused on doing functional programming with a lot of expressions. Code shown in the examples is harder to understand and change than “oldschool” if/else or switches. It has it purposes but it also has its limitations. Be vary with implementation, not everything is suitable everywhere. That aside great presentation and very interesting to watch! Kind regards.

  • @jhdk356
    @jhdk356 Před 2 lety +10

    Since they are advancing the pattern matching this much, I really wish they would introduce uniontypes etc. similar to typescript - it just seems it would be a good match, making it possible to e.g. return different types in a method, and the caller can then choose to handle this using pattern matching with type checks for the more limited amount of possible types (opposed to using e.g. object as return object).

  • @twiksify
    @twiksify Před 2 lety

    Nice presentation! Property matching is a really cool feature, however they only work with const values. It won't work if you need to check against another object, at least not yet.

  • @shaihulud4515
    @shaihulud4515 Před 2 lety

    I found your typo "Nothing SPACIAL about this" in terms of geometry very charming :)

  • @nmarcel
    @nmarcel Před 2 lety +11

    A sad caveat is that the evaluated values must be compile time constants, which in many (or most?) cases makes the feature simply useless. I mean, who really hard code parameters?

  • @Amy_A.
    @Amy_A. Před rokem

    For a lot of these more "flavorful" features in other languages, I feel they're overly specific and cause more problems than they solve (looking at you, CSS). This seems fantastic, though. It's clear, concise, and customizable. Great video, thanks for the tips!

  • @TheRoundedTable
    @TheRoundedTable Před 2 lety +3

    Started learning Haskell recently, so this is extremely interesting.
    Do you know if there is a way to utilise a Predicate directly in the is {} syntax? Or do I absolutely have to make it in a separate condition(Ex: s is {} && myPredicate(s.Width))?
    For example:
    if (s is Rectangle { Width: Equals42 })
    Where "Equals42", is a predicate that will receive a width in parameter and return true if it's 42, and false otherwise.

  • @brianm1864
    @brianm1864 Před 2 lety

    I knew the power of pattern matching in the switch expressions, but I had no idea you could do it in an if statement. That's awesome! Question though.... how could you (if at all possible) do pattern matching on a class property where you want to do .StartsWith or something like that? So I want to do something like - if (vehicle is Car { color: StartsWith("Blue") }), where color is a string. I know that's an oddball example, just trying to show what I'm asking :)

  • @bahabbj5798
    @bahabbj5798 Před 2 lety

    Thanks nick , I want the resource that contains this topics

  • @Denominus
    @Denominus Před 2 lety +2

    C# pattern matching is getting there, I mostly use it nowadays to simplify multiple conditions. If/when union types arrive, domain modelling and logic in C# is going to look wildly different from today.
    In the short term, I'd like to see them add support for expression statements so you can use switch expressions to execute different code paths. Either that or support for Unit (nothing) as a type, but that's much less likely.

  •  Před 2 lety

    Hi Nick, thanks for another interesting video. I am wondering, isn't dangerous to have two switch conditions about different properties of an object as both of the conditions can be true at the same time?
    And what is happening here in the compiler code? Just nested if else statements?

  • @ryanzwe
    @ryanzwe Před 2 lety

    Nice

  • @Ziplock9000
    @Ziplock9000 Před 2 lety

    When I first seen this back in C#8 I thought this was very powerful, but in practice there's not as many cases where I can use it in day-to-day code.

  • @Layarion
    @Layarion Před 2 lety +5

    i really like how in your vids you go through the whole history. helps give needed perspective.
    also, too bad we can't just type "area 100-200" instead of "area greater than 100 and less than 200"

    • @UberAffe1
      @UberAffe1 Před 2 lety

      There probably could be a notation to identify "between", but you would need identifiers for; inclusive of both, inclusive of lower, inclusive of higher, and exclusive of both.

    • @niiiiiiiiiiiia
      @niiiiiiiiiiiia Před 2 lety

      Hmm now that there is System.Range, probably we should request the ability to use not only `Area: >=100` or `Area:

    • @duytrananh2292
      @duytrananh2292 Před 2 lety

      No worries, just make feedback to Microsoft and see the magic on the next version of C#

  • @matesomogyi6545
    @matesomogyi6545 Před 2 lety

    Perfect way to hide/forget the else paths, the "what happens if not" scenarios, which may missing from the requirements.

  • @nucasspro1
    @nucasspro1 Před 2 lety

    Can I write the block code inside a case of switch and return the same type as other cases? Or only one line? Thanks

  • @ibrahimhussain3248
    @ibrahimhussain3248 Před 2 lety

    Wow 🤩🤩🤩

  • @ivanpavlovnorth
    @ivanpavlovnorth Před 2 lety

    Very useful video for an interview question: What new features have C# versions?

  • @jasonargo9085
    @jasonargo9085 Před 2 lety

    As long as the patterns being matched are consts / readonly, in a general sense will the runtime be faster than, say, the same amount of variables being checked with the classic if else statements?

  • @TheTripleDeuce
    @TheTripleDeuce Před rokem

    what would you suggest to do in C# to have a small image and find it in a running program? like a screenshot image within any particular program for example

  • @mosth8ed
    @mosth8ed Před 2 lety

    Do you happen to know if there are any available benchmarks for performance in using these types of complex matches in a switch? Most of my C# is done in Unity for games and tools, and most of the time when I see something neat, easy to use, and powerful (ex. Linq, etc) it ends up being something you absolutely do not want to use in a game loop due to allocations and often overall performance in general. Being that this is an actual built-in language feature and not just a convenience package, I am wondering if it would be more "safe" to use in situations where performance matters greatly?

  • @raygan3
    @raygan3 Před 2 lety +1

    What happens if two expressions in the switch statement are matched then which one will return? Does the order matter?

  • @sagielevy
    @sagielevy Před 11 měsíci

    Pattern matching in C# is awesome, but one thing that really bugged me was that variables that were declared via pattern matching would not allow you to declare another variable of their name even when they went out of scope. For example if in some method i had an `if (a is Circle c) {...} and then `if (b is Circle c) {...}` it won't compile saying that `c` is already declared. But it not! The first `c` can only exist inside the scope of the first `if`. Swift handles this well. I hope C# would too

  • @Sygmond
    @Sygmond Před 2 lety +1

    I was using some of this and I didn’t know that is called pattern matching. I was always wondering what is the recommended way: “shape != null” or “shape is not null”. At a moment I was debating with my coleague that we should use one or the other, to keep the same style everywhere. Now I understand that the second style is the new way and is ok to use it.

    • @duytrananh2292
      @duytrananh2292 Před 2 lety

      I have done a few test and both of them executed at same time, so u can use both without worrying or which one is better. But i still prefer the old school operator != bevause its easier to read haha

    • @raygan3
      @raygan3 Před 2 lety

      @@duytrananh2292 the new way is easier to read because you can read the code as a book you dont have to convert != operator in your brain into the not keyword

  • @JustinMinnaar
    @JustinMinnaar Před rokem

    What is the shortcut command to change a string from "" to $"" while editing in it?

  • @hj.0301
    @hj.0301 Před 2 lety

    will it hit nullReferenceException? if yes, can we do a null conditional operator? if (randomShape is Rectangle { ShapeInShape?.Area: 100 }) ?

  • @Jashobantac
    @Jashobantac Před 2 lety

    Nick some videos on AOP if possible...

  • @BrokenSword17
    @BrokenSword17 Před 2 lety

    We both have the same exact chair.

  • @RawCoding
    @RawCoding Před 2 lety +1

    underrated feature

    • @WillEhrendreich
      @WillEhrendreich Před 2 lety

      Underrated C# teacher! You're great bro, thanks, you've helped me a lot! haha.

  • @IvanArdillo
    @IvanArdillo Před 2 lety

    Does it work with regular expressions?

  • @khalilsayhi4958
    @khalilsayhi4958 Před 2 lety

    Hi Nick, do you offer end of studies internship opportunities? can i apply as a software engineering student for a 6 month internship?

  • @matthewtrip2124
    @matthewtrip2124 Před 2 lety +1

    How does your Rider have c#10 and net6 support

    • @nickchapsas
      @nickchapsas  Před 2 lety +1

      Rider EAP is out with some support for C# and net 6

  • @JasonPoggioli
    @JasonPoggioli Před 2 lety

    What's the reasoning for starting to use 'and' and 'or' in pattern matching like this instead of && and || ? Because it's an extension to linq syntax?

    • @nickchapsas
      @nickchapsas  Před 2 lety

      It doesn't have anything to do with LINQ. It's just a different operator

  • @raghavgupta1157
    @raghavgupta1157 Před 2 lety

    This went crazier each second. C# is a big deal!!

  • @marcelius8649
    @marcelius8649 Před 2 lety +1

    10:35 wish they code also introduce between operator on c# 10

    • @Ziplock9000
      @Ziplock9000 Před 2 lety

      I think there is it's ".." possibly?

  • @iGexogen
    @iGexogen Před 2 lety

    Is last example from C# 10 with accesing area of nested object is null safe?

    • @nickchapsas
      @nickchapsas  Před 2 lety

      Depends on whether the reference is nullable or not

    • @iGexogen
      @iGexogen Před 2 lety

      @@nickchapsas So your example will throw NRE cause you never initialized inner shape, but example with nested braces will not. Are ?. null-conditional operators allowed in pattern matching to avoid this?

    • @nickchapsas
      @nickchapsas  Před 2 lety

      @@iGexogen The C# 10 example has nullable reference types enabled so it assumes that the value will not be null. If there was an option for it to be null then it wouldn't be compiling

  • @LukeVilent
    @LukeVilent Před 2 lety

    So, in a nutshell, C# just absorbs all the useful features of python, and making them even better. I wonder when we shall have (or do we already have?) variable typization, of the sort Union[TypeA, TypeB,...] of Python.

  • @marka3797
    @marka3797 Před 2 lety

    Hi Nick, wanna work with under your supervise.

  • @LCTesla
    @LCTesla Před rokem

    it's nice to have options I guess, but I struggle to see how this is ever more readable than classic if-then-else syntax.

  • @TechLover135
    @TechLover135 Před 2 lety

    You say circle with area but then use the diameter instead 😅 otherwise great video like always, considering to sign up for Patreon

    • @nickchapsas
      @nickchapsas  Před 2 lety +3

      You can tell that I was sleeping during my geometry lessons

  • @mistermeua
    @mistermeua Před 2 lety

    Isn't an example with checking for type is an example of beaking a OCP?

    • @nickchapsas
      @nickchapsas  Před 2 lety

      I wouldn't say so. If you have a unit test returns IActionResult and you wanna check if the result is OkObjectResult for some assertions purposes to access the underlying Value or StatusCode properties then that's a perfectly valid case, and there are hundrends other like it.

    • @mistermeua
      @mistermeua Před 2 lety

      @@nickchapsas thanks for your attention. I didn't expect to get an answer from you personally)
      A case you described is acceptable for type checks as far as I see.
      But on the other hand I would like to warn beginners: if in production code you check for type and it has an impact on a code flow - this is a reason to reconsider a way you solving your problem.
      I guess my point is next: language features(syntax su gar) do not allow breaking a clean coders practices. These features are to make your code cleaner and readable.
      Thanks

  • @andersborum9267
    @andersborum9267 Před 2 lety +1

    I highly recommend all interested developers to interactively follow along in VS; it's really some very nice enhancements to the C# language that (among some of the more esoteric features they're adding) provide real production value imo.

    • @rohansampat1995
      @rohansampat1995 Před 2 lety

      Lol except hes usring rider, though either IDE should work fine. GG

  • @Layarion
    @Layarion Před 2 lety

    2:56 couldn't I use if randomShap == circle ?

    • @nickchapsas
      @nickchapsas  Před 2 lety

      That just checks if the references are the same

  • @sohampatel1063
    @sohampatel1063 Před 2 lety

    C# is functional c++ and the best language ever made

  • @boondocksripoff2237
    @boondocksripoff2237 Před 2 lety

    Has he covered the performance of using ‘var vs int,string,double’ ?

    • @shexec32
      @shexec32 Před 2 lety

      Don't know if Nick did a video on this, but I do know the answer.
      In C#, there is zero runtime performance cost to using var vs explicit typing, since the compiler automatically converts vars back to the strong types during compilation.
      You could argue that var is slightly quicker to compile because there are fewer characters in var than string & double, meaning the compiler has to read fewer bytes from disk. But this is a very contrived scenario: in what circumstances would you care about compilation performance and source code file size?
      That's your extra credit assignment.

    • @boondocksripoff2237
      @boondocksripoff2237 Před 2 lety

      @@shexec32 thanks for the reply, I was just curious ,I'm kind of new to c# ,coming from c++, I thought var would be the same as auto in c++.

  • @pilotboba
    @pilotboba Před 2 lety

    I think sometimes this syntactic sugar makes the code less readable. Let's not get too close to Perl. :)

  • @ZeroSleap
    @ZeroSleap Před rokem

    Why did they change it up and the "and" logical operator in the patterns is well "and" and not "&&" like im used to...

  • @metaltyphoon
    @metaltyphoon Před 2 lety

    The only thing missing is being able to run expressions / statements from the pattern matching results itself.

    • @PlerbyMcFlerb
      @PlerbyMcFlerb Před 2 lety

      A workaround is IIFEs. Create a Func and immediately invoke it.

  • @dimakoss5142
    @dimakoss5142 Před 2 lety

    The best feature of c# is that you usually able to use other language xD

  • @bronzekoala9141
    @bronzekoala9141 Před rokem

    if (randomShape is Circle {Radius: 10})
    thats such a weird Syntax. Why isn't it the same as in switch?
    if (randomShape is Circle cir when cir.Radius == 10)
    Edit:
    Ah I see - you can do the following:
    if (randomShape is Circle cir && cir.Radius == 10})
    I guess this isn't the default because it assigns a new- probably otherwise unused variable?

  • @mirabilis
    @mirabilis Před rokem

    I use "is casting" all the time.

  • @juanmiguel4682
    @juanmiguel4682 Před 2 lety +1

    Thanks. Its nice, cool and useful in many cases, but some syntacs are a little ofuscated, so if you abuse using this, you could be writing no clean code. Clean code is one of the main objetives when you write code. You should not write code as a demostration to your partners of your clever mind. Your code should be clear and understable to everyone, and many times is not the compact way. Thanks.