[Solved] New to C#, can anyone explain to me how enums and setting variables for enums works? [closed]


An enum is basically a special type that lets you define named values. You’re creating a named type just as you would if you were defining a class. What your code is actually doing is first defining your enumerated type called States with all the possible named values, then declaring a variable “myState” using the enum type “States” that you defined in the line before. What you can’t see in your code is that by default in c# the underlying type for your enum is an integer, and each of your possible values also has an integer value assigned to it which could be overridden if needed, so all you’re really doing in your update code is an integer comparison. Is there any reason you’re not using a switch instead of that big if/else block? Also you could eliminate the start function and just instantiate your myState variable like this:

private States myState = States.cell;

MSDN has pretty good documentation for it here:

https://msdn.microsoft.com/en-us/library/sbbt4032.aspx

3

solved New to C#, can anyone explain to me how enums and setting variables for enums works? [closed]