Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 28-01-2010
Rum Rum is offline
Member
 
Join Date: Dec 2009
Posts: 17
Enums VS Struct

I am the beginner programmer in the vast programming world. The programming has become so vast in this days, the technology is growing day-by-day. Right i am learning the programming language like C++, C sharp, Java, DBMS and PHP. Actually i have query in C sharp, what is difference between the Enum(enumeration) and Struct(structure)? Please help me.
Reply With Quote
  #2  
Old 28-01-2010
Member
 
Join Date: Jan 2008
Posts: 1,515
Re: Enums VS Struct

Enums: It is mainly a set of named constants. And they are specified by using the enum keyword. Each 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.
Struct: Structure are the stack objects and they are defined by using the struct keyword. However much you try you cannot create them on the heap. Structure is created from one variable of a primitive type or by combining various variables of primitive types.
Reply With Quote
  #3  
Old 28-01-2010
Member
 
Join Date: Feb 2008
Posts: 1,848
Re: Enums VS Struct

The structure(struct) is a value type and the instances or objects of a structure are made on stack. Structure is made from one variable of a primitive type or by combining various variables of primitive types.The struct can have fields--methods--constants--constructors--properties--indexers--even other structure types. The Enum(Enumerations) are a unique type which contains a set of named constants called as "enumerator list". Enums are integer types which will create code clearer and easier to maintain.
Reply With Quote
  #4  
Old 28-01-2010
Member
 
Join Date: May 2008
Posts: 2,383
Re: Enums VS Struct

I can't explain the difference between enum and struct theory wise ,but can give you good practical example of both of them, which can clear your doubt and can see the difference between them. Example:
STRUCTURE:
struct vehicle
{
char name[25];
char modelno[25];
char owner[25];
double cost;
};

ENUMERATION:
enum vehicle
{
TwoWheeler,
FourWheeler,
};
Hope your problem get solve.
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #5  
Old 28-01-2010
Member
 
Join Date: Oct 2005
Posts: 2,389
Re: Enums VS Struct

Structures(struct) are made as a lightweight which can be alternate option to classes. Struct are almost same to classes and this structure we can include constructor's, operators, properties, methods, nested types, and indexers. Enum(enumerations) gives us a powerful alternate option to the literal or simple symbolic constants. An enumeration is a unique value type, which has a set of named constants (called the enumerator list). This enumeration begins with the enum keyword.
Reply With Quote
  #6  
Old 28-01-2010
Member
 
Join Date: Nov 2005
Posts: 1,323
Re: Enums VS Struct

Structures(struct) and Enumerations(enum) are Value-Types and this means the data which is going to be handle/stored as a stack on the memory. Structures are implicitly derived from a class called System.ValueType. A struct can contain fields, methods, constants, constructors, properties, indexers, operators and even other structure types. Enum is the keyword which use for defining the enumeration. The enumeration is a unique type which consist of a set of named constants called the enumerator list. Every enumeration has an underlying type. The default type is 'int'.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Enums VS Struct"
Thread Thread Starter Forum Replies Last Post
Struct and Strings in C Ash maker Software Development 5 05-04-2010 12:31 PM
C++ struct vs class avvia Software Development 3 13-07-2009 10:53 AM


All times are GMT +5.5. The time now is 04:38 AM.