Array with values of an Enum ?

Hello

I’m trying create an Array with values of an Enum, but still can’t do this.

I’m trying this.

public class EnumWords : MonoBehaviour {

	public enum getWords{
        BOLO, 
        BOLA, 
        COLA,
        DADO
    };    
}


public class WordsControl : MonoBehaviour {
       
    private string[] words = EnumWords.getWords;

}

how can I do this ?

I believe your array class is wrong. enum getWords doesn’t contain strings, it contains aliased values… This is the documentation for how enums in C# work.

I believe you want:

private getWords[] words = EnumWords.getWords.GetValues;

That isn’t the correct syntax, but it’s the gist. Read the docs I linked for a better understanding.

or something along those lines. Enums are essentially type enforced numbers. (And in C++ and C that is all they.)

Simplest is to hand-make it:

string[] getWordsStrings = {"Bolo", "Bola", Cola", "Colo"};

As Slev mentions, enums aren’t strings, and aren’t supposed to be printed. The only thing they do is replace if(door1Status==2) with if(door1Status==doorStatus.Locked), to make code easier to read. Retyping the words for the array feels sort of hacky, because it is.

If you really want a string array, use Enum.GetNames, it returns a string array.

string enumstrings = Enum.GetNames(typeof(EnumWords.getWords));

As already stated by @Owen-Reynolds and @Slev, this is not the best use of enum’s which are meant to be fast and used by whatever integral you define(default to int(int32)), which make them sexy smart when combining(bitwise operations) values to make an end result.

I am a super noob, but I THINK I accomplish this op’s goal with this. you need to define the enum, then you need to actually create an enum array of that type for use in the class:

 public enum aggressionType
    {
    	neutral,
    	passive,
    	aggressive,
    	fearful,
    	helpful
    }
    public aggressionType[] m_aggressionType;

update: I think I was wrong. I’ve just created an enum array, but op wants to draw from an already-created enum array to get its values, so the other answers probably work better for that need.