This is a discussion on What is the difference between structures and enumeration? within the VB.NET Programming forums, part of the Software Development category; What is the difference between structures and enumeration?...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Hi anbuchezhian Structures and Enumerations are Value-Types. This means, the data that they contain is stored as a stack on the memory. Classes are Reference-Types, means they are stored as a heap on the memory. Structures are implicitly derived from a class called System.ValueType. The purpose of System.ValueType is to override the virtual methods defined by System.Object. So when the runtime encounters a type derived from System.ValueType, then stack allocation is achieved. When we allocate a structure type, we may also use the new keyword. We may even make a constructor of a structure, but, remember, A No-argument constructor for a structure is not possible. The structure's constructor should always have a parameter. So if we define the following structure Code: struct MyStruct
{
public int y,z;
} MyStruct st = new MyStruct(); In case of a class, no-argument constructors are possible. Class is defined using the class keyword. A struct cannot have an instance field, whereas a class can. Code: class A
{
int x = 5; //No error
...
}
struct
{
int x = 5; //Syntax Error
} A class can inherit from one class (Multiple inheritance not possible). A Structure cannot inherit from a structure. Enum is the keyword used to define an enumeration. An enumeration is a distinct type consisting of a set of named constants called the enumerator list. Every enumeration has an underlying type. The default type is "int". Note: char cant be the underlying data type for enum. First value in enum has value 0, each consequent item is increased by 1. enum colors {red, green, blue, yellow}; Here, red is 0, green is 1, blue is 2 and so on. An explicit casting is required to convert an enum value to its underlying type Code: int x = (int)colors.yellow; Oxygen |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| looping structures in Ruby? | vadivelanvaidyanathan | Ruby | 1 | 08-18-2007 12:53 AM |
| difference between an enumeration and a set of preprocessor #defines? | prasath | C and C++ Programming | 1 | 08-17-2007 11:36 PM |
| Difference between enumeration and iterator in java? | kingmaker | Java Programming | 3 | 08-08-2007 02:53 AM |
| How can do test the Pointers & Structures? | sundarraja | Software Testing | 1 | 07-30-2007 09:54 PM |
| Difference of Structures and Classes | vigneshgets | C and C++ Programming | 1 | 05-24-2007 10:53 AM |