Structs and Enums
What is a Struct in C# ? what is the difference between Struct and Enum in C# ?
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
AdministratorRank #675 · 3.6K reputationPosted Feb 19, 2003, 8:23 AM EST
AdministratorRank #675 · 3.6K reputationPosted Feb 19, 2003, 8:28 AM EST
PradeepRank #6,279 · 271 reputationPosted Feb 24, 2015, 8:22 PM EST
Enums are basically a set of named constants.
They are declared in C# using the enum keyword.
Every enum type automatically derives from System.
Enum and thus we can use System.Enum methods on our Enums.
Enums are value types and are created on the stack and not on the heap.
You don't have to use new to create an enum type.
Declaring an enum is a little like setting the members of an array as shown below.
enum Rating {Poor, Average, Okay, Good, Excellent}
structs are stack objects and however much you try you cannot create them on the heap.
structs cannot inherit from other structs though they can derive from interfaces.
You cannot declare a default constructor for a struct, your constructors must have parameters.
The constructor is called only if you create your struct using new,
if you simply declare the struct just as in declaring a native type like int,
you must explicitly set each member's value before you can use the struct.
Hope this help you