Mohan Gupta
What is difference between Enum and Struct?
By Mohan Gupta in C# on Jun 11 2013
  • Krishna Mohan
    Apr, 2014 17

    1.The enum keyword is used to declare an enumeration 2.Enum represents a set of Named constants( we cannot change the values associatedwith enums since Enums are treated as Constants).3.Enum will be having an underlying type as Integral Type. (Except Char )4.The default underlying type of the enumeration elements is int5.By default, the first enumerator has the value 0, and the value of each successive enumerator is increased by 16.Enums are value types7.Enumerations (enums) make your code much more readable and understandable.8.We can declare Enum either in a class or out side of a class as well9.Enum cannot inherit from other Enum.Note:Double and Float are not Integral types but they are Floatingpoint types I hope this points are enough for understanding Enums.StructStructs (structures)0. Struct is just like class but is light weight and faster.1.Within a struct declaration, fields cannot be initialized unless they are declared as const or static. 2.A struct may not declare a default constructor (a constructor without parameters) or a destructor.3.Structs are value types and classes are reference types. 4.All structs inherit directly from System.ValueType, which inherits from System.Object. 5.Struct Contains only Parameterized Constructors and No Destructors.6.Wecan directly intialize the const or static fileds in the Struct.7.we can implement interfaces in structs but we cannot inherit a struct from other struct or class.8.Because copies of structs are created and destroyed automatically by the JIT compiler,a default constructor and destructor are unnecessary.9.Structs are By Default sealed. 10.Value types are faster than ref types. 11.Most of the Primitive types in .NET are Structs. 12.Better to declare a struct instead of a class when the Total size of all fields is less than 16 bytes(this is not a rule ).This are the points regarding Struct I hope by reading this you can understand the diffrence between the struct and Enums for learning more about this type of question you can refer this link also. c# interview questions

    • 1


Most Popular Job Functions


MOST LIKED QUESTIONS