Structure versus class

Similar to a class in C#, a struct is also a data structure that consists of members, functions, and so on. Classes are reference types, but structs are value types; hence, these are not required for heap allocation but for allocation on the stack.

Value type data will be allocated on stack and reference type data will be allocated on heap. A value type that is used in struct is stored on the stack, but when the same value type is used in an array, it is stored in a heap.

So, when ...

Get Learn C# in 7 days now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.