Results 1 to 6 of 6

Thread: Enums VS Struct

  1. #1
    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.

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    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.

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    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.

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    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.

  5. #5
    Join Date
    Oct 2005
    Posts
    2,393

    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.

  6. #6
    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'.

Similar Threads

  1. Struct and Strings in C
    By Ash maker in forum Software Development
    Replies: 5
    Last Post: 05-04-2010, 12:31 PM
  2. C++ struct vs class
    By avvia in forum Software Development
    Replies: 3
    Last Post: 13-07-2009, 10:53 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,007,522.50542 seconds with 17 queries