C# Programming - Control Instructions - Discussion
Discussion Forum : Control Instructions - General Questions (Q.No. 13)
13.
Which of the following statements are correct?
- A switch statement can act on numerical as well as Boolean types.
- A switch statement can act on characters, strings and enumerations types.
- We cannot declare variables within a case statement if it is not enclosed by { }.
- 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.
- All of the expressions of the for statement are not optional.
Discussion:
3 comments Page 1 of 1.
Samar said:
9 years ago
Why statement 3 is not true?
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!
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers