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.
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.
PradeepPosted Feb 25, 2015, 1:22 AM
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
AdministratorPosted Feb 19, 2003, 1:28 PM
AdministratorPosted Feb 19, 2003, 1:23 PM