What?s different about switch statements in C#?
Answers were Sorted based on User's Feedback
Answer / 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 |
What is the difference between console and windows application?
How do you declare an arraylist?
What?s the top .NET class that everything is derived from?
What are c# i/o classes?
Explain 'structure padding'?
Can overrride the Main method
Why it's said that writing into .NET Application Configuration Files is a Bad Idea?
why we can't create an object for a static class?? what is the reason behind this?
What is the default value of guid in c#?
What is the best dependency injection c#?
how dot net compiled code will become platform independent?
How do I automate my desktop application?