C# 10 Part 2 - Records, Structs and Record Structs

Поділитися
Вставка
  • Опубліковано 31 тра 2024
  • All the benefits of a record but in a value type? Introducing the record struct.
    Source code available at: github.com/JasperKent/CSharp-...
  • Наука та технологія

КОМЕНТАРІ • 11

  • @CodingTutorialsAreGo
    @CodingTutorialsAreGo  2 роки тому +1

    Any more C# 10 you want to know about? Let me know.
    Source code at: github.com/JasperKent/CSharp-10-Part-2
    Remember to subscribe at ua-cam.com/channels/qWQzlUDdllnLmtgfSgYTCA.html
    And if you liked the video, don't forget to click the 👍.

  • @RobertoDeMontecarlo
    @RobertoDeMontecarlo Рік тому +3

    This channel should be top... great content and solid lessons. Thanks!

  • @rustamhajiyev
    @rustamhajiyev 2 роки тому +2

    I hope that with C# 11 we'll finally get union types🤞

  • @imikhan83
    @imikhan83 Рік тому +1

    Very nice explanation... thanks

  • @ThomasLorenz1
    @ThomasLorenz1 2 роки тому +3

    Can you tell me where are the use cases for record structs ?

    • @CodingTutorialsAreGo
      @CodingTutorialsAreGo  2 роки тому +2

      It's hard to be definite about. I don't use structs much, so I don't use record structs much. But my instinct is, if you're going to write a struct, make it a record struct, then you're helped with immutability and given all the free methods.

  • @SharafMansour
    @SharafMansour 2 роки тому +1

    Would not it be useful to have a default constructor for record class ?

    • @CodingTutorialsAreGo
      @CodingTutorialsAreGo  2 роки тому +1

      Yes, you can add one to a record class if you want.

    • @SharafMansour
      @SharafMansour 2 роки тому

      @@CodingTutorialsAreGo I mean getting one out of the box. Like in normal class.

    • @SharafMansour
      @SharafMansour 2 роки тому

      Trying to understand C# team POV. When record classes came without a default constructor. I have to manually define them.

    • @CodingTutorialsAreGo
      @CodingTutorialsAreGo  2 роки тому +2

      @@SharafMansour They do. But by using the positional syntax (putting the properties in brackets after the record name) you are declaring a constructor with parameters. And so, just like with a class, adding any constructor turns off the auto-generation of a default constructor.