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

Can constructor have return type c#?

0 Answers  


What do you mean by default constructor?

0 Answers   NIIT,


how to store the value in textbox using delegates if we have two user control. the value will be called from one user control to another user control. Loading and unloading will be done through delegates.

1 Answers  


What are the Types of JIT and what is econo-JIT

0 Answers   TCS,


i have a question which is quite simple but yet complicated for me my question is why do we use void, if it does not return anything to the compiler? if it is used for normal display it can also be done by what is called Console.Write() or Consol.WriteLine() and if i do not use void with my method then my compiler throws me an error. if i return a value say integer then i write public int fun() display of the result can also be done here then why is it so necessary to use void with a function and why so compiler throw us an error if v don't use void return type?

2 Answers  






What is the size of a decimal?

0 Answers  


Can scriptable objects have methods?

0 Answers  


What is ControlBox Propertie

0 Answers   MCN Solutions,


Why delegates are safe in c#?

0 Answers  


What is the use of tryparse in c#?

0 Answers  


Define parsing? Explain how to parse a datetime string?

0 Answers  


What is static and use of it?

0 Answers  


Categories