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
what is a structure in c#
Why is it efficient to use System.string under System.Text.StringBuilder ?
Can an interface extend a class c#?
What are functions c#?
How do you comment in c#?
Can an abstract class have a constructor c#?
Can you specify nested classes as partial classes?
Explain when should you call the garbage collector in .net?
Is constructor a static method?
What is the keyword used to prevent a class from being inherited by another class?
What is access modifier in c#?
Explain the difference between arraylist and array and in c#?
What is deadlock in c#?
Can we extend sealed class in c#?
What is form feed and carriage return?