如何Foreach enum
namespace ConsoleDemo
{
class Program
{
static void Main(string[] args)
{
foreach (Area area in Enum.GetValues(typeof(Area)))
{
Console.WriteLine(area);
}
}
public enum Area
{
Africa, Australia, America, Asia, Europe
}
}
}
執行結果:
Africa
Australia
America
Asia
Europe