Home
Manage Your Code
Snippet: Iterate through an enum (C#)
Title: Iterate through an enum Language: C#
Description: Iterate through an enum Views: 826
Author: Chris Gaskell Date Added: 6/26/2007
Copy Code  
1//By Value
2foreach (int i in Enum.GetValues(typeof(Colors)))
3{
4	Console.WriteLine(i);
5}
6
7//By Name
8foreach (string s in Enum.GetNames(typeof(Colors)))
9{
10	Console.WriteLine(s);
11}
12