C# Programming - Enumerations - Discussion

Discussion Forum : Enumerations - General Questions (Q.No. 2)
2.
Which of the following statements is correct about the C#.NET code snippet given below?
int a = 10; 
int b = 20; 
int c = 30;
enum color: byte
{
    red = a, 
    green = b,
    blue = c 
}
Variables cannot be assigned to enum elements.
Variables can be assigned to any one of the enum elements.
Variables can be assigned only to the first enum element.
Values assigned to enum elements must always be successive values.
Values assigned to enum elements must always begin with 0.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
4 comments Page 1 of 1.

Sridhar said:   7 years ago
Please explain with an example.

Devcorner said:   8 years ago
Enumeration is named integral constants. You can store only the value types in the enum, In c# we have only two types of value types there are enum and struct because it can store the equivalent value in a stack, not in heap.

K2u2007 said:   1 decade ago
An enumeration is a set of named integer constants. The keyword enum declares an enumerated type. The general form for an enumeration is enum name { enumeration list };
Here, the type name of the enumeration is specified by name. The enumeration list is a comma-separated list of identifiers.

Here is an example. It defines an enumeration called Apple that enumerates various types of apples:

enum Apple { Jonathan, GoldenDel, RedDel, Winesap,
Cortland, McIntosh };

A key point to understand about an enumeration is that each of the symbols stands for an integer value.

Sudhir Singh said:   1 decade ago
Enum is of byte data type and variables is of int type.

Post your comments here:

Your comments will be displayed after verification.