Jun 30, 2023

Structs in C# are fun - Part 1/9

Leia este post em português

Lisez cet post en french.

Value types (and consequently, structs) existed in .NET since its inception, yet they are still a source of confusion in 2023 (at least for me). So I decided to collect a list of subjects, that may or may not be so obvious to some .NET developers, and I'll discuss them in the following posts (I'll update the list adding links as I post about each topic):

  1. This post.
  2. Brief introduction to Value Types vs Reference Types.
  3. Field initialization in structs.
  4. Constructors and struct behavior.
  5. Other scenarios in which struct constructors behavior may surprise you.
  6. Struct with default argument values in constructors, a.k.a, are you not confused yet ?
  7. `required` feature from C# 11 will not save your a** job.
  8. Struct used as default argument values.
  9. Bonus: Struct evolution in C#.

Before continuing, note that this series reflects the current state of C# as of version 11 (.NET 7.0).

Last, but not least, even if you are an experienced C# developer I hope you can learn something or, why not, add your own perspective/contribution to the subject.

As always, all feedback is welcome.

Have fun!

No comments: