Compare structs and classes in C#. What do they have in common
Loading
Compare structs and classes in C#. What do they have in common
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Mukul SinghPosted Jun 17, 2025, 5:52 AM
Both structure and class are used to define custom data types.Classes is a reference type while structs is a value type. Classes are used to represent complex objects with multiple properties and method whereas struct is used to represent basic data types like integer, string etc. Struct are lighweight than classes and more suitable for functions that require high performance and low memory usage. Classes are less efficient than struct but can support inheritance and polymorphism that allows for more flexible and modular code.
E.g.