C# Programming - Control Instructions - Discussion

Discussion :: Control Instructions - General Questions (Q.No.4)

4. 

What is the output of the C#.NET code snippet given below?

namespace IndiabixConsoleApplication
{
    public enum color
    { red, green, blue };
    
    class SampleProgram
    {
        static void Main (string[ ] args)
        {
            color c = color.blue;
            switch (c)
            {
                case color.red:
                    Console.WriteLine(color.red); 
                    break; 
                
                case color.green: 
                    Console.WriteLine(color.green); 
                    break; 
                
                case color.blue: 
                    Console.WriteLine(color.blue); 
                    break; 
            } 
        } 
    } 
}

[A]. red
[B]. blue
[C]. 0
[D]. 1
[E]. 2

Answer: Option B

Explanation:

No answer description available for this question.

Neeraj Goyal said: (Mar 27, 2013)  
Because here in this case only color blue object is created first then we entering in the switch case so that's why answer must be blue.

Bharat Bhusan Nanda said: (Sep 3, 2014)  
color c = color.blue;.
After that the value of 'c' is 'blue'.

c = blue.
So, the output will be 'blue'.

Vishal Daware said: (Oct 5, 2016)  
We are using <Color.blue > so it will print color name, otherwise if it prints only blue then the answer will be 2 because Enum values start with 0 and so on.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.