What is ENUM?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is an escape sequence? Name some string escape sequences in c#.

516


What is lastindexof c#?

484


What does it mean to override a method?

469


What is a void c#?

510


What is the difference between Static, Const and read only?

536






Is static thread safe?

490


What is dll file in c#?

522


what is scope of a protected internal member variable of a c# class

536


Is c# or c++ better for games?

466


What is the reason behind the invention of c#?

631


What are the Types of optimization and name a few and how do u do?

526


What is difference between variable and property in c#?

432


What is private in c#?

488


What is a concrete class in c#?

532


Does c# support c type macros?

557