In what situation when Struct is better than Class | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

In what situation when Struct is better than Class

28th Aug 2021, 1:38 PM
Tim
Tim - avatar
7 Answers
+ 4
Have you already check 68.1 of the sololearn c# course? There's a structs vs. classes section
28th Aug 2021, 4:04 PM
Lisa
Lisa - avatar
28th Aug 2021, 1:55 PM
CodeSmith
CodeSmith - avatar
+ 2
Using my consolidated knowledge of C++ and C#, I would say that structures and unions have been architected to provide a composite datatype, which results in efficient memory management, and classes are essentially the translation of static data into dynamic datastrucures, that can spawn methods, and provide the functionality of OOPS like method and operator overloading, and can be instantiated as OBJECTS, which can be garbage collected like in the .NET GC.Collect() method, which mops up the objects created in the heap. IMHO the first 2 datastructures are created on the stack, as a general rule. They are static and cannot be instantiated as OBJECTS.🙃 Hope this helps !🧙‍♂️
30th Aug 2021, 6:55 AM
Sanjay Kamath
Sanjay Kamath - avatar
+ 2
Sanjay Kamath Well explained 👍
30th Aug 2021, 7:23 AM
Tim
Tim - avatar
+ 2
Nick Danke schön ! 🙃
30th Aug 2021, 8:03 AM
Sanjay Kamath
Sanjay Kamath - avatar
+ 1
Martin Taylor You can't have a method in a Struct?
28th Aug 2021, 1:54 PM
Tim
Tim - avatar
+ 1
Lisa Oh, I'll have a look, see if I can get more insight, thanks for the reminder 👍
28th Aug 2021, 7:30 PM
Tim
Tim - avatar