Enum Question

  • Thread starter Thread starter CuMPeEWeEr [No MCSD]
  • Start date Start date
C

CuMPeEWeEr [No MCSD]

public enum Color {Red=1; Yellow=2; Orange=3; }

Is there a way to get the value of the Color easily? I know it can be done
using Enum.GetValues(typeof(Color)) but I have to use a for-loop to get the
value in this case. Is there a direct way to get the value? something like
Enum.GetValue(Color.Red) and returns 1?

Thanks..
 
Hi,

If I understand your question correctly, you what to get the constant that
represents an enum. To do this you can cast the enum to an integer.

int i = (int)Color.Red;

Hope this helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top