C# Programming - Control Instructions - Discussion

Discussion Forum : Control Instructions - General Questions (Q.No. 13)
13.
Which of the following statements are correct?
  1. A switch statement can act on numerical as well as Boolean types.
  2. A switch statement can act on characters, strings and enumerations types.
  3. We cannot declare variables within a case statement if it is not enclosed by { }.
  4. The foreach statement is used to iterate through the collection to get the desired information and should be used to change the contents of the collection to avoid unpredictable side effects.
  5. All of the expressions of the for statement are not optional.
1, 2
2, 3
3, 5
4, 5
None of these
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
3 comments Page 1 of 1.

Sundar said:   1 decade ago
using System;

public class Test
{
public static void Main()
{
Boolean b=false;

switch (b)
{
case true:
Console.WriteLine("True is okayed! ");
break;
case false:
Console.WriteLine("False is okayed! ");
break;
default:
Console.WriteLine("Default");
break;
}
}
}

//output:
False is okayed!

Mahdi said:   1 decade ago
Numerical contains double float and decimal and switch does not work with these types.

Samar said:   9 years ago
Why statement 3 is not true?

Post your comments here:

Your comments will be displayed after verification.