C# Programming - Enumerations - Discussion

Discussion :: Enumerations - General Questions (Q.No.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 

[A]. Variables cannot be assigned to enum elements.
[B]. Variables can be assigned to any one of the enum elements.
[C]. Variables can be assigned only to the first enum element.
[D]. Values assigned to enum elements must always be successive values.
[E]. Values assigned to enum elements must always begin with 0.

Answer: Option A


No answer description available for this question.

Sudhir Singh said: (Mar 6, 2013)  
Enum is of byte data type and variables is of int type.

K2u2007 said: (Oct 3, 2014)  
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.

Devcorner said: (Nov 19, 2016)  
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.

Sridhar said: (Jun 11, 2018)  
Please explain with an example.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.