+ 1
In what situation when Struct is better than Class
9 RĂ©ponses
+ 4
Have you already check 68.1 of the sololearn c# course? There's a structs vs. classes section
+ 3
This post will help
https://stackoverflow.com/questions/54585/when-should-you-use-a-class-vs-a-struct-in-c#:~:text=I%20would%20recommend%20you%3A,default%20constructors%20and%20operators%2C%20etc.
+ 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 !đ§ââïž
+ 2
Sanjay Kamath
Well explained đ
+ 2
Nick Danke schön ! đ
+ 1
Martin Taylor
You can't have a method in a Struct?
+ 1
Lisa
Oh, I'll have a look, see if I can get more insight, thanks for the reminder đ