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
What is thread life cycle in c#?
What are strong name assemblies?
What is a Jagged Array in C#?
What is this keyword in C#?
Can you change the value of a constant filed after its declaration?
What is difference between comparable and comparator?
What are c# collections?
What Is The Smallest Unit Of Execution In .net?
update data in an xml file which resides in solution itself, using silverlight 4.0
Is lazy t thread safe?
What is readline library?
What is difference between association, aggregation and inheritance relationships?
What is a cshtml file?
For read-only operation which property you have to designated?
What is difference between assembly and dll?