C# 9 Language Features

Поделиться
HTML-код
  • Опубликовано: 3 июн 2024
  • C# 9 is one of the most exciting features that developers are expecting with the release of .NET 5.0.
    In this episode, Jared Parsons joins Rich to show us some of the language enhancements we can look forward to in this new update to C#.
    [01:20] - What can developers expect from C# 9?
    [01:55] - Understanding Records
    [10:32] - How Records handle type equality
    [13:18] - Record immutability
    [16:28] - Making the case for init properties
    [21:41] - Multiple types in the same file???
    What's new in C# 9?
    docs.microsoft.com/en-us/dotn...
    Welcome to C# 9
    devblogs.microsoft.com/dotnet...
    C# Today & Tomorrow
    channel9.msdn.com/events/Buil...
    Get your questions answered on the Microsoft Q&A for .NET - aka.ms/dotnet-qa​
    Learn .NET with free self-guided learning from Microsoft Learn: aka.ms/learndotnet
    #dotnet #csharp
  • НаукаНаука

Комментарии • 184

  • @xenopheliac7202
    @xenopheliac7202 3 года назад +32

    Love that C# keeps growing functional. Soon I won't have to beg people to do Haskell at work.

    • @willinton06
      @willinton06 3 года назад +3

      @@PaulSebastianM too abstract for most, including me

    • @obinator9065
      @obinator9065 3 года назад +1

      @@PaulSebastianM don’t like the syntax

  • @TNothingFree
    @TNothingFree 3 года назад +15

    When I learned Kotlin all I was thinking was "Why C# doesn't have it?"
    You can see real progress when you look at new languages like Kotlin and Rust which are absolute stunning from my point of view.
    Because they already implement immutability and record classes.
    Awesome!

    • @obinnaokafor6252
      @obinnaokafor6252 3 года назад +1

      Scala is better with those things.

    • @reubenator
      @reubenator 3 года назад

      "Stunning" is the correct word, when a language construct just allows you to express your intent without the word salad. I actually love that these languages continue to evolve, refine and learn from each other, it ultimately helps us devs "get to the point"

    • @matsalritzson3492
      @matsalritzson3492 3 года назад +2

      It doesn't go only one way. Rust is copying async/await from C#.

  • @AlexFeature
    @AlexFeature 3 года назад +3

    The one thing that I absolutely love about C# is its elegance. It is such an intuitive and beautiful language.

  • @JosephHerrington
    @JosephHerrington 3 года назад +4

    With the changes in 7.x, 8 and now 9, it seems like they are laying the groundwork for transitioning to a more Functional style of programming. This reminds me of Scala. And I’ve always been a fan of Scala!

  • @calvinwilson3617
    @calvinwilson3617 3 года назад +3

    Bringing some of the advantages of js/ts into C# just in time for blazor, i love it

  • @Conficient
    @Conficient 3 года назад +1

    Great description of records and why you would use them, thanks

  • @briannielsbergh
    @briannielsbergh 3 года назад +1

    one word: AWESOME!!!!.....love the progress in the C# language.... .P Keep up the good work.

  • @nissanGold
    @nissanGold 3 года назад +1

    Wow records look like a really good and valuable feature!
    Great job dev team :)

    • @obinnaokafor6252
      @obinnaokafor6252 3 года назад +1

      Yes it is very a valuable feature. Soon we will have record struct also. And these underpinning would help pave way for a better and superior discriminated union (DU) feature in C#.

  • @ehsnils
    @ehsnils 3 года назад +1

    One thing that I think that records should have is a way to declare common fields for multiple records, especially for the case where you have the records stored in a database table where you want to have a unified declaration of primary key.

  • @konstantinsarychev9305
    @konstantinsarychev9305 3 года назад +1

    Nice, but what about lists (or other custom ref types) inside records? Are the also going to be compared by content? And are they also get assigned by cloning the entire content?

  • @aregaz21
    @aregaz21 3 года назад

    Love your explanation, guys. Thanks for making this video 👍

  • @simplegameplay1469
    @simplegameplay1469 3 года назад +6

    Definitely looking forward to use C# 9, 8 was an amazing entry. Now is there any way of making infix functions or there will be?

  • @bar10dr
    @bar10dr 3 года назад

    Awesome video, great dev presentation

  • @beshy9012
    @beshy9012 3 года назад +36

    I love c#.net core

    • @johnthetactician5139
      @johnthetactician5139 3 года назад +7

      Hell yeah, screw Java

    • @charlesbaldo
      @charlesbaldo 3 года назад +1

      N7 Commander John
      Adopt Blazor and you can screw JavaScript too.

    • @hanspetervollhorst1
      @hanspetervollhorst1 3 года назад +2

      waiting for go#

    • @willinton06
      @willinton06 3 года назад

      @@hanspetervollhorst1 G#

    • @cascadengineering
      @cascadengineering 3 года назад

      Blazor is not fit for interactive web-sites and is worse than React+TypeScript+ModX where you can also leverage SignalR to talk to C# API.

  • @SJ-mp2hk
    @SJ-mp2hk 3 года назад

    This was awesome! Thank you 🙏🏾

  • @helshabini
    @helshabini 3 года назад +3

    I wonder how would records work with EF. If I change an object in my context via a wither, will it change the record value in the database or recreate it with a brand new Id?

  • @lbobrov
    @lbobrov 3 года назад +2

    I remember, that somewhen in the years between 2000 and 2007, there was a video podcast series which was called "The .NET Show" with Erica Wiechers :)

    • @ericnyamu9981
      @ericnyamu9981 3 года назад +1

      does the female name make it easy to remember the show ? lol

    • @SOMEONE-eq5bu
      @SOMEONE-eq5bu Год назад

      @@ericnyamu9981 lol 😂😂🤣🤣, good point

  • @jackshen1028
    @jackshen1028 3 года назад +1

    Haskell has a huge code base for the immutable record style

  • @zemom.a.8171
    @zemom.a.8171 3 года назад +5

    I wonder if theres ever gonna be rust-like memory handling?
    Instead of creating Verona to implement safe memory deallocation why not make this a thing in C# for the devs that need it?

  • @r1pfake521
    @r1pfake521 3 года назад +9

    What's the behavior of records with "advanced" types instead of basic string or int, for example will it be possible to add a List or Dictionry property to a record? How will it be immutable, since the List itself can still be changed?
    How will the copy (with expression) work with these types, will it "copy" the list reference or will it create a real copy of the list?
    How will it work with custom types as record properties, how will it be able to copy these or will it just "copy" the reference of these properties?

    • @yusufmohamedsalh8321
      @yusufmohamedsalh8321 3 года назад +2

      I think video is quite non explainory ,the one should try it himself

    • @rabidtommy
      @rabidtommy 3 года назад

      Asking all the difficult questions, ones which will need answers

  • @joshdeshazer1698
    @joshdeshazer1698 3 года назад +1

    I love it ready to use records. Thank you team

  • @facundo91
    @facundo91 3 года назад +9

    07:58 You mean "p1 == p3: {isEqual}". Please add a note, otherwise is confusing.

  • @Rafael-vn2bo
    @Rafael-vn2bo 3 года назад +98

    C# 9, years ahead of Java.

    • @ryanleemartin7758
      @ryanleemartin7758 3 года назад +28

      F# 4, years ahead of C#9 . Sorry, I couldn't help myself.

    • @danielecerro3797
      @danielecerro3797 3 года назад +18

      @@ryanleemartin7758 Q#, billions years ahead?

    • @charlesbaldo
      @charlesbaldo 3 года назад +8

      Daniele Cerro
      Z# the Omega

    • @ryanleemartin7758
      @ryanleemartin7758 3 года назад +4

      @@danielecerro3797 HA! well If quantum computing was actually real, maybe. Let's hope!

    • @ryanleemartin7758
      @ryanleemartin7758 3 года назад +3

      @@charlesbaldo Shit. I'd try Z# the Omega.

  • @tbg10101
    @tbg10101 3 года назад

    When will I be able to use some of these nice things with readonly structs?

  • @Rauly4557
    @Rauly4557 3 года назад

    Very Cool!

  • @FilipCordas
    @FilipCordas 3 года назад +1

    I like typescript syntax with {...p1} then the f# way makes a bit more sense. On that question can you use with keyword with two different record types?

    • @Kitulous
      @Kitulous 3 года назад

      Why would you need it? 'with'-expression allows you to get an existing record WITH some other properties. If you need to fully overwrite the record just pass the second one lol.

    • @FilipCordas
      @FilipCordas 3 года назад

      @@Kitulous It just a personal preference mostly because it would work for arrays as well not just objects. And this is not only a see for using modified object you do use it for shallow copies as well

  • @NevadaWilliford
    @NevadaWilliford 3 года назад +1

    Personally, I think this looks great. Also, very clearly presented. Great job.

  • @Samiron
    @Samiron 3 года назад

    Is the record reference type? Can I create value type "record"?

  • @IBITZEE
    @IBITZEE 3 года назад +1

    That guy really knows his stuff...

  • @RayHorn5128088056
    @RayHorn5128088056 3 года назад

    Could have done record with a smart superclass but what they hey. Kudos for the effort.

    • @obinnaokafor6252
      @obinnaokafor6252 3 года назад

      What do you mean by "with a smart superclass"? Just asking an honest question. Thank you.

    • @Kitulous
      @Kitulous 3 года назад +3

      @@obinnaokafor6252 Probably something like
      class Person : Record {}
      which would take care of equality and stuff

    • @RenegadeVile
      @RenegadeVile 3 года назад

      @@Kitulous Wouldn't you, at some point, still need to define the equality comparison, for example? A member-by-member comparison? This is something that record also avoids. If you add a new property to Person, but forget to add it to your equality check, you've introduced a sometimes subtle bug.

  • @phantastik3389
    @phantastik3389 3 года назад

    I hope you guys have a book ready so can study c#9

  • @TheRetrospective
    @TheRetrospective 3 года назад

    Now that one sees this, it's so obvious. I'm only wondering why this wasn't part of C# much earlier, like 10 years ago? I guess sometimes innovation takes time to emerge and implement.

    • @orlovsskibet
      @orlovsskibet 3 года назад

      Your user name is so much embodied in your comment 😁

  • @DheerajUthaiah
    @DheerajUthaiah 3 года назад

    Wow!!

  • @marcosrocha
    @marcosrocha 3 года назад +1

    So, we might substitute our POCO classes for records?

    • @s3rg3yg
      @s3rg3yg 3 года назад +4

      And DTOs

    • @RenegadeVile
      @RenegadeVile 3 года назад

      That's pretty much what records would be useful for yeah.

  • @3N35
    @3N35 3 года назад

    Voavv. Çok iyi olmuş.

  • @rehanahmed6210
    @rehanahmed6210 3 года назад

    👍👍👍

  • @paulfunigga
    @paulfunigga 3 года назад +3

    A whole zoo of features

  • @siyabongadlamini2904
    @siyabongadlamini2904 3 года назад

    I love it

  • @hanspetervollhorst1
    @hanspetervollhorst1 3 года назад +4

    Can you define methods on records?

    • @r1pfake521
      @r1pfake521 3 года назад +4

      Yes, it's just "syntax sugar" they are still normal classes, you can even subclass them.

    • @RenegadeVile
      @RenegadeVile 3 года назад

      Like the other commenter said, all record does is generate common operations for value types for you. So member-by-member equality comparison, etc. things you would commonly do when implementing interfaces like IEquatable. But beyond that, it's still just a class so you can do everything else with them that you can with a class. However, once you start considering adding complex methods and states to your record, you should start asking yourself the question whether it should be a record at all.

  • @mp9508
    @mp9508 3 года назад +4

    Syntactic saccharin.

    • @chrissolutions
      @chrissolutions 3 года назад

      @@JP-hr3xq Disagree. I love switch expressions.

  • @brunoccs
    @brunoccs 3 года назад

    What's the difference between struct and record?

    • @willinton06
      @willinton06 3 года назад

      Deconstruction is easier

    • @ikanreed816
      @ikanreed816 3 года назад +2

      Records aren't value types, regardless of whether they're mutable, they're still passed up and down the stack as references.

  • @user-gt2gy8wo3h
    @user-gt2gy8wo3h 3 года назад

    Could you pls share the vim emulator extension name you were using in VS?

    • @obinnaokafor6252
      @obinnaokafor6252 3 года назад +2

      marketplace.visualstudio.com/items?itemName=JaredParMSFT.VsVim

    • @ifelseprog
      @ifelseprog 3 года назад +1

      He wrote it, by the way

  • @yusufmohamedsalh8321
    @yusufmohamedsalh8321 3 года назад +3

    Hi Jared,you should press 'insert' to get rid of the cursor.

  • @krigrtrue
    @krigrtrue 3 года назад

    Where is extend everything

  • @mariacobretti
    @mariacobretti 3 года назад

    PogChamp

  • @3D_Printing
    @3D_Printing 3 года назад

    "Hello world,"

  • @Novalarke
    @Novalarke 3 года назад +2

    C#9? I know it well:
    C#, E#, G#, B and D#
    .
    .
    .
    What?
    Oh.

  • @freezefrancis
    @freezefrancis 2 года назад

    Records are just scala case classes i believe

  • @mihaimyh
    @mihaimyh 3 года назад

    So, records are the way to go from now on, we ditch classes?

    • @zemom.a.8171
      @zemom.a.8171 3 года назад +1

      Well, records ARE classes.
      And in OOP,mutating states are sometimes requires.
      If you, for example, have a UI system and bind a textbox to a string-property to determine a class's state, then making the class immutable would be counter-productive since often times user-input needs to mutate object-state.

    • @r1pfake521
      @r1pfake521 3 года назад

      @@zemom.a.8171 I always wonder what kind of software the "everything immutable" people develop, because I can't see how developing something like editor with UI or games with so many game states would work reasonable without mutable objects, it sounds like a horrible mess to me, but maybe im just not lighted by the power of "everything immutable" yet.

    • @matsalritzson3492
      @matsalritzson3492 3 года назад +6

      @@r1pfake521 In a proper functional programming language you have copy on write. Under the hood it's still references to the same objects. But once you start to change something you create a copy of it and do your modifications there. The cool thing is that this simplifies stuff alot when dealing with threading. Some stuff will be more difficult, but others will be alot easier.

    • @RenegadeVile
      @RenegadeVile 3 года назад +1

      No, records will be primarily useful for DTOs or plain old data classes. If you have any experience with C++, for example, there we would use structs that just contain some public members and that's it. For things that still require methods, state or complex logic, you'll still want to use classes. Especially if you need reference semantics for your type as opposed to value.

  • @Esico6
    @Esico6 3 года назад

    Feedback from customers? Which customers? C# and .Net is free.

    • @piromanaBG
      @piromanaBG 3 года назад

      You can pay for support

    • @willinton06
      @willinton06 3 года назад

      RUclips is free yet we’re RUclips customers

  • @clay9963
    @clay9963 3 года назад +6

    He uses vsvim...

  • @ihorbond
    @ihorbond 3 года назад

    Amazing! Excited to try these out in the .net 5 app I'm about to build for a client !

  • @crash1998100
    @crash1998100 3 года назад +2

    18:20 Why not just use readonly

    • @zemom.a.8171
      @zemom.a.8171 3 года назад

      Yeah...

    • @r1pfake521
      @r1pfake521 3 года назад +4

      One difference between readonly and init is that you can set init properties in an object initializer syntax which is not possible with readonly

    • @crash1998100
      @crash1998100 3 года назад

      @@r1pfake521 Oh, I thought it was. Kinda weird that's not possible for readonly

    • @davidmil15
      @davidmil15 3 года назад

      @@crash1998100 it’s not weird really. The initializer syntax is just sugar for setting properties and that happens after construction.

  • @gavinlangley8411
    @gavinlangley8411 3 года назад

    Record sounds great but you need the idea of key, key matching and data not equal. So you need something like Record as (TKey, TValue) ...

  • @tarasov9794
    @tarasov9794 3 года назад

    It's a bit disturbing to see a space between method name and {, and no space between method name and (. But at least you use the superior bracing method. ;)

  • @jasonracey9600
    @jasonracey9600 3 года назад +2

    Every new C# version comes with a "new" feature that Scala has already had for a decade. Maybe C# 10 will have Option[T]? Or function currying? Or everything immutable by default? Place your bets.

    • @RenegadeVile
      @RenegadeVile 3 года назад +2

      Nearly every feature from every language has been done at some point somewhere else. Keep in mind that they're not claiming to have invented the wheel here. This is a new feature FOR C#, not a new feature among all programming languages.

  • @bruceke13
    @bruceke13 3 года назад +2

    OMG MY EYES, THE WHITEMODE

  • @Zapanath
    @Zapanath 2 года назад

    I guess we can get rid of F# now. Records is only new to C# , F# devs have had records for ages.

  • @CoryTaylor904
    @CoryTaylor904 3 года назад

    So basically, they are picking f# features and running with it.

  • @LivingTheDream21
    @LivingTheDream21 3 года назад +4

    I feel like Rich Lander is abrasive or condescending.
    1:06
    6:02
    and probably more, but I'm just at the 6 minute mark.

  • @wizardarss
    @wizardarss 3 года назад +6

    Such magic only hurts. Make better compilation with CoreRT. Good innovations: stack allocated, intrinsiсs, BCL optimization, nothing else.

    • @zemom.a.8171
      @zemom.a.8171 3 года назад

      Project snowflake/Rust-like deallocation would also be a very nice tool for developing every application thats involved in the media/digital art industry.

  • @NativeEngine2017
    @NativeEngine2017 3 года назад

    Only C++ )))

    • @RenegadeVile
      @RenegadeVile 3 года назад

      My mind went straight to C++ too at the sight of record.

  • @madmonad3678
    @madmonad3678 3 года назад

    Sadly immutability is still not fully embraced; as "x with { ...}" is a poor substitute for value optics like lenses.
    Secondly it's ridiculous that C# still hasn't added a discriminated union type similar to F#.

  • @nitsanbh
    @nitsanbh 3 года назад

    “Records” exist in Python and Kotlin for years now... they’re called “Data Classes”

    • @RenegadeVile
      @RenegadeVile 3 года назад +1

      WEll, in all fairness, in C# itself, they're also existed since its inception. Either use structs or implement the required overrides and interfaces in a class. This is just a quality of life improvement.

  • @westernvillager
    @westernvillager 3 года назад

    Very nice talk! But please improve your typing 😜

  • @47Mortuus
    @47Mortuus 3 года назад

    delegate*

  • @user-dy8dl6xu5w
    @user-dy8dl6xu5w 3 года назад +3

    Too weird syntax

    • @obinnaokafor6252
      @obinnaokafor6252 3 года назад +1

      How is it weird? Could you clarify?

    • @user-dy8dl6xu5w
      @user-dy8dl6xu5w 3 года назад

      1. Why can not create a new instance "inline" without a ctor without the new keyword init? (duplicate ctor for example)

    • @willinton06
      @willinton06 3 года назад

      @@user-dy8dl6xu5w that’s as old as time, it’s not a C# 9 feature

  • @janjoska2549
    @janjoska2549 3 года назад

    Jees, use resharper.

  • @anomalii7720
    @anomalii7720 3 года назад +3

    Hmmm, something i will NOT use.

    • @vivekvenugopal8411
      @vivekvenugopal8411 3 года назад +1

      That makes two of us

    • @r1pfake521
      @r1pfake521 3 года назад

      Same, for these "dumb" serialization classes I never cared about value equality, constructor deconstruct or anything like that, so they only contain public get, set properties which isn't really that much code and I would rather have the "default" reference equality in the rare cases where equality is used for example if I have to remove these objects from a list or dictionary I want to remove the actual instance I pass and not some other instance which has the same values.

  • @kotzulla
    @kotzulla 3 года назад +1

    someone still using c#????

    • @RenegadeVile
      @RenegadeVile 3 года назад +1

      Yes? A lot of people? A lot of people also still use C and C++, both to great effect. Programming language is just a tool. It's much more important how you use it, and what you use it for.

    • @jake8217
      @jake8217 3 года назад

      Oh my sweet summer child...

    • @dsmyify
      @dsmyify 3 года назад

      It feeds the family.

  • @uthoshantm
    @uthoshantm 3 года назад +11

    I feel C# is becoming more and more bloated.

    • @sps014
      @sps014 3 года назад +10

      I Don't think so, C# is evolving in the right direction.

    • @nissanGold
      @nissanGold 3 года назад +13

      Most of these features look like syntatic sugar if you dont want to learn it you dont have to.

    • @brokula1312
      @brokula1312 3 года назад +1

      @@nissanGold And how do you know what you have to or not to learn?
      It is bloated. Beside C++ probably the biggest bloat in industry.

    • @obinnaokafor6252
      @obinnaokafor6252 3 года назад +3

      That is a very wrong notion to hold. C#/ .NET is still one of the top fastest and most productive platform out there. With record, one can cut down all the ceremonies and boilerplates codes. Unless you are being paid by the lines of code you write?

    • @obinnaokafor6252
      @obinnaokafor6252 3 года назад +7

      @@brokula1312 So you would want C# to just remain the way it is since 20 years ago? If not there would not have been LINQ, Lambdas, async await, extension method etc. Languages which are still relevant evolve. And C# is still one of the relevant languages out there. Records are good with machine learning and building models. And it helps cut down some boilerplates. Even Java is getting reocrds.

  • @josephang9927
    @josephang9927 2 года назад

    I hate that fat cursor.

  • @asadahmed4993
    @asadahmed4993 3 года назад +3

    Haha copying python now! no wonder Python is the boss 😎

    • @obinnaokafor6252
      @obinnaokafor6252 3 года назад +3

      Async & await? Linq and Lambdas? Auto-properties? Lol

    • @piromanaBG
      @piromanaBG 3 года назад +5

      Sorry: IndentationError

    • @paulwojcik1856
      @paulwojcik1856 3 года назад +4

      Have just learnt Python (for a real job), been programming professionally since DOS 3.3 and have used every language you can imagine. Thank god I have C# for my job (Windows/Linux/Cloud + embedded) and don't have to use Python all the time, what an awful piece of work that is. Passing self to every class member so that it knows it is itself (even though I indented under a class def), really? Its like handing myself my own picture and ID every morning just to know who I am when I wake up. And what about a ++ operator so I can increment values inline (C and C++ had it when python come along) or a simple switch statement, huh? Maybe Python should get the basics right before bragging :-)

    • @milisha98
      @milisha98 3 года назад +2

      @Asad Ahmed Records were found in many languages before Python was even a twinkle in Guido van Rossum's eye. Even other Microsoft languages, such as F# even has had records and discriminated unions since inception.

    • @RenegadeVile
      @RenegadeVile 3 года назад +1

      No language is the boss. Depends on what you need done.

  • @Esico6
    @Esico6 3 года назад +1

    This is so ugly. Yak.

  • @marcusreinicke7352
    @marcusreinicke7352 3 года назад

    Excuse me, but I find most innovations easy especially those that were not shown, just garbage.
    Most changes make the source code less legible. Unfortunately, this is not an innovation, it is something that very specific people wished for.
    It seems to me that you don't have any decent ideas for improving the C # language.
    Maybe you should turn away from C # slowly, because the straight lines are becoming more and more weakened.
    That's my personal opinion, but it makes me sad to see C # continue to degenerate. I would advise a programming team to forbid C # 9.0 in the style guides.
    Only bad