Let’s say I have the following enum:
public enum Colors
{
White = 10,
Black = 20,
Red = 30,
Blue = 40
}
I’m wondering if there is a way to iterate through all the members of Colors to find the member names and their values.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use Enum.GetNames and Enum.GetValues:
Note: When I tried to run the code using
values[i], it threw an exception becausevaluesis of typeArray.