csharp Enum Questions & Answers

Question 1: What will be the output of the following program?

enum WeekDays
{
    Monday,
    Tuesday,
    Wednesday,
    Thursday,
    Friday,
    Saturday,
    Sunday
}

Console.Write(WeekDays.Monday);

Question 2: What will be the output of the following program?

enum WeekDays
{
    Monday,
    Tuesday,
    Wednesday,
    Thursday,
    Friday,
    Saturday,
    Sunday
}

Console.Write( (int)WeekDays.Monday);

Question 3: What will be the output of the following program?

enum WeekDays
{
    Monday,
    Tuesday,
    Wednesday,
    Thursday,
    Friday,
    Saturday,
    Sunday
}

var holiday = WeekDays.Sunday;
Console.Write(“{0}, {1}”, holiday, (int) holiday);
ADVERTISEMENT

Question 4: The members of the enum are always public, and no access modifiers can be applied.

Question 5: What will be the output of the following program?

public class Program
{
	public static void Main()
	{
		WeekDays.Sunday = 12;
		Console.Write(WeekDays.Sunday);
	}
}

enum WeekDays
{
    Monday,
    Tuesday,
    Wednesday,
    Thursday,
    Friday,
    Saturday,
    Sunday
}