C# Programming - Control Instructions - Discussion

Discussion Forum : 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; 
            } 
        } 
    } 
}
red
blue
0
1
2
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
4 comments Page 1 of 1.

Vishal Daware said:   9 years ago
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.
(1)

Neeraj goyal said:   1 decade ago
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:   1 decade ago
color c = color.blue;.
After that the value of 'c' is 'blue'.

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

Sakthivel said:   2 years ago
How can I use it as dynamic as it's been in static?

Anyone, please explain me.

Post your comments here:

Your comments will be displayed after verification.