Foreach enum(列舉型別)

  • 73
  • 0

如何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