Compare structs and classes in C#. What do they have in common
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Mukul Singh35 reputationPosted Jun 17, 2025, 1:52 AM EDT
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.
struct Person { public string Name; public int Age; }Class PersonClass { public string Name; public int Age; }