What is ENUM?

Answers were Sorted based on User's Feedback



What is ENUM?..

Answer / pijush

The enum keyword is used to declare an enumeration, a
distinct type consisting of a set of named constants called
the enumerator list. Every enumeration type has an
underlying type, which can be any integral type except
char. The default underlying type of the enumeration
elements is int. By default, the first enumerator has the
value 0, and the value of each successive enumerator is
increased by 1. For example:

Is This Answer Correct ?    23 Yes 2 No

What is ENUM?..

Answer / srinivasan

Enum is a type for which the memory will be allocated on the stack instead of the heap. It can be used to write presentable code in place where we will be using integers. For Ex.

Enum Declaration

private Enum OperationalResult
{
Success = 1,
Failure = 2
}

Enum Usage

Switch (result)
{
case: (int)OperationalResult.Success
MessageBox.Show("Yippe,Operation Success");
break;
case: (int)OperationalResult.Failure
MessageBox.Show("OOPS! It's a failure");
break;
default:
MessageBox.Show("OOPS! Canno determine");
break;
}

Here in the above code, if the following statement
(int)OperationalResult.Success is replaced with 1, it does not make sense and a new developer looking at the wouldn't understand what 1 represents.

Is This Answer Correct ?    5 Yes 0 No

What is ENUM?..

Answer / muthukumar

The enum keyword is used to declare an enumeration, a
distinct type consisting of a set of named constants called
the enumerator list. Every enumeration type has an
underlying type, which can be any integral type except
char.

Is This Answer Correct ?    4 Yes 0 No

What is ENUM?..

Answer / thirupathi reddy katkoori

It is a data type in C-language. It is used determine the unique values

Is This Answer Correct ?    4 Yes 2 No

What is ENUM?..

Answer / nishesh

ENUM is a user defined data type. and it is declared to hold constant values for a set of data
example

enum days {sun,mon,tue,wed,thur,fri,sat}

will assign values like this
sun=0
mon=1
tue=2
and so on
if we want to use that series then we can do like this

int First_day=(int)days.sun;

it will give

First_day = 0

Is This Answer Correct ?    2 Yes 0 No

What is ENUM?..

Answer / gnanavel s

enum is a keyword that allows you to declare an enumeration. an enumeration is a set of names for valeus. for example

enum Dificulty {easy,normal,hard};

then you can declare variables of type Dificulty and set it's value as easy/normal/hard

Dificulty d = Dificulty.easy;

enums make your program more readable and help you to don't set integer values incorrectly. remembering easy is easier than remembering 0 or 1. a complete reference is available on MSDN [here.][1]

as you can read there the value is easy is 0 and normal 1 and hard 2. values are increased by one and you can set the values to numbers that you want. the type is a constant integral type. by constant i mean that you can not change the value of Dificulty.easy after defining the enum.

unity uses enums for sending constant values to functions. you can see enums usefulness from Input.GetMouseButton() i always froget what number is for what button but if it had an enum like

enum MouseButton {left,middle,right};

then it was easy to set this just like KeyCode and other available enums.

using enums in javascript is the same but i don't know how to define them in js.

hope this helps.

Is This Answer Correct ?    0 Yes 0 No

What is ENUM?..

Answer / javamasque

1. Enum is implicitly final subclass of java.lang.Enum.
2. if an enum is a member of a class, it is implicitly static.
3. The keyword “new” can never be used with an enum, even within the enum type itself.
4. For enum constants, “equals” and “==” is same thing, and can be used interchangeably.
5. Enum constants are implicitly public static final.
6. The enum constants are its instances.
7. Only private modifier can be used before it’s constructor.
8. Enum can implement interface but can’t extends any class
9. We can override only toString() method to return any custom string.
10. The static method values() return all enum constants in an order as it found inside enum class.
11. The instance method name() returns string value of enum constant.

Is This Answer Correct ?    0 Yes 0 No

What is ENUM?..

Answer / jagwinder singh

An Enumeration is a set of named integer constants. The keyword enum declares an enumerated type.

Here is example:

enum Apple { Jonathan,Goldendel, reddel,winesap}

by default jonathan has value 0,goldendel=1 and so on

Is This Answer Correct ?    0 Yes 1 No

What is ENUM?..

Answer / kiran

It’s used to define constants

Is This Answer Correct ?    0 Yes 2 No

What is ENUM?..

Answer / kotu

ENUM is defind as to Assign Constens, These Constents are
Unique.

Is This Answer Correct ?    2 Yes 9 No

Post New Answer

More C Sharp Interview Questions

What is helper method in c#?

0 Answers  


What is delegate in c# interview questions?

0 Answers  


Explain why do I get an error (cs1006) when trying to declare a method without specifying a return type?

0 Answers  


Can you override private virtual methods?

11 Answers   AROBS Transilvania Software, IBM, Mind Tree, Revalsys,


Define satellite Assembly in .NET?

0 Answers   DELL,






What is a collection class in c#?

0 Answers  


What is difference between static and constant variable?

0 Answers  


Define multicast c# delegate?

0 Answers  


Is double a decimal?

0 Answers  


What is a template class?

0 Answers  


Describe the process of “exception handling implementation” in c#?

0 Answers  


Why do we use abstraction in c#?

0 Answers  


Categories