Answer Posted / ranganathkini
C#'s switch statements have the following features:
1. It does not allow automatic fallthrough in non-empty
cases. Example:
int i;
switch( i ) {
case 0:
// FALL THRU ALLOWED
case 1:
Console.WriteLine( "The case is 1" );
// FALL THRU NOT-ALLOWED, break or goto required
default:
Console.WriteLine( "Unknown case" );
break;
case 2:
Console.WriteLine( "The case is greater than 1" );
break;
}
2. The order of the default case does not manner. It need
not have to be the last case. Illustrated in the above example.
3. Unlike C++ or Java, C#'s switch allows a variable of type
string to be tested. Example:
Console.Write( "Enter name of country: " );
string country = Console.ReadLine();
switch( country ) {
case "India":
Console.WriteLine( "Welcome to India" );
break;
case "USA":
Console.WriteLine( "Welcome to USA" );
break;
default:
goto case "India";
}
4. Use of goto statement to switch from one case label to
another. See above example.
| Is This Answer Correct ? | 8 Yes | 0 No |
Post New Answer View All Answers
Explain how do I get deterministic finalization in c#?
What is the difference between a constant and a static readonly field?
Explain the difference between private and shared assembly?
What is task parallel library?
How do you pronounce c#?
What is the value which is accepted by all data types ?
Can an interface extend a class c#?
How big is an int in c#?
Is c# pass by reference?
What is append in c#?
Why is lazy loading?
What is as keyword in c#?
What is static variable in c#?
Explane each and every methods of nterface Queue? Explain About performance issues on retrieving records
Why do we use static class in c#?