C# Structs

Structs are a useful thing to know about when writing C#. Here’s an intro to understand and help you use them!

Structs in C# are value types, meaning that they hold their data values directly, whereas classes are reference types, meaning they hold a reference to the object containing their data.

They are very similar to classes, in that they can hold data variables and methods.

Structs can contain variables just like classes

Properties:

  • Struct members are public by default.
  • Structs don’t require a constructor.
  • Structs cannot be inherited from.
  • Structs are value types and are stored on the stack, not heap.
  • Structs are better for small amounts of data.
  • Structs cannot have the protected accessor.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vincent Taylor

Vincent Taylor

Unity game developer / C# Programmer / Gamer. Australian (Tasmanian) indie games developer for 10+ years. Currently looking for games industry employment.