Demonstrate an enumeration

image_pdfimage_print

using System;

public class EnumDemo {
enum apple { Jonathan, GoldenDel, RedDel, Winsap,
Cortland, McIntosh };

public static void Main() {
string[] color = {
“Red”,
“Yellow”,
“Red”,
“Red”,
“Red”,
“Redish Green”
};

apple i;

for(i = apple.Jonathan; i <= apple.McIntosh; i++) Console.WriteLine(i + " has value of " + (int)i); Console.WriteLine(); for(i = apple.Jonathan; i <= apple.McIntosh; i++) Console.WriteLine("Color of " + i + " is " + color[(int)i]); } } [/csharp]

This entry was posted in Data Types. Bookmark the permalink.