C# Corner
Tech
News
Videos
Forums
Trainings
Books
Events
More
Interviews
Jobs
Live
Learn
Career
Members
Blogs
Challenges
Certifications
Bounties
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
.NET
ADO.NET
Android
ASP.NET
C#
Databases & DBA
Design Patterns & Practices
Java
Learn iOS Programming
OOP/OOD
SharePoint
Software Testing
Web Development
WPF
View All
1
Reply
What is difference between Enum and Struct?
Mohan Gupta
12y
25.3k
1
Reply
Delete Row
Delete Column
Insert Link
×
Insert
Cancel
Embed YouTube Video
×
Width (%)
Height (%)
Insert
Cancel
Table Options
×
Rows
Columns
First row as header
Create Table
Insert Image
×
Selected file:
Alignment
Left
Center
Right
Select an image from your device to upload
Upload to Server
Cancel
Submit
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
Krishna Mohan
11y
1
What is using keyword in C#?
What is difference between an Array and ArrayList?
Message