Ivo Manolov
Oct 3, 2023

--

C# structs are allocated on the stack unless "boxed". when "boxed" they are copied to the heap and must be garbage collected like a class instance. Same as the int , float ect.

It's important to clarify that the storage location of structs can vary depending on the programming language and context in which they are used. The statement you provided is not universally true for all programming languages and situations.

In many programming languages, structs are indeed stored on the stack when they are used as local variables within a function. This is particularly true in languages like C# and C++. When you declare a struct as a local variable in a function, it is typically allocated on the stack, and its memory is automatically deallocated when the function exits.

--

--

Ivo Manolov

I write technical articles to share my knowledge and help others navigate the ever-evolving tech landscape. Technical Know - How / Software Interview Hacks.