- Home /
Enum Count
Any way to get this to work (c#)?
public enum Stats {Strength, Intelligence, Wisdom, NUM_STATS};
private int[Stats.NUM_STATS as int];
Comment
Sorry, that was a dumb question.
public enum Stats {Strength, Intelligence, Wisdom, NU$$anonymous$$_STATS};
private int[] stats = new int[(int)Stats.NU$$anonymous$$_STATS];
works just fine for anyone searching for this.
Best Answer
Answer by Graham-Dunnett · Aug 13, 2013 at 08:39 PM
using UnityEngine;
using System.Collections;
public class test : MonoBehaviour {
public enum myenum
{
value1 = 0,
value2,
NumberOfTypes
}
// Use this for initialization
void Start () {
Debug.Log((int)myenum.NumberOfTypes);
}
}
thanks, that worked but also, i'm an idiot:
public enum Stats {Strength, Intelligence, Wisdom, NU$$anonymous$$_STATS};
private int[] stats = new int[(int)Stats.NU$$anonymous$$_STATS];
works just fine :|
Answer by derPuppeteer · Jun 14, 2014 at 07:39 PM
I would not recommend doing it like this. Better do it like this:
using UnityEngine;
using System.Collections;
public class test : MonoBehaviour {
public enum myenum
{
value1,
value2
}
// Use this for initialization
void Start () {
Debug.Log(System.Enum.GetValues(typeof(myenum)).Length);
}
}
Just wanted to add that I remember reading on StackExchange about GetNames being faster than GetValues for some reason.