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 |
Can you inherit from a sealed class?
Can we make a class private in c#?
Are c# objects passed by reference?
What is interface inheritance?
What is tochararray in c#?
What is callback function in c#?
what is a destructor?
Is c sharp and c# are same?
What is piller of OOPS in C#.
How to authenticate web service? When you enter the web service url in browser it should ask username and password. After entering the un&pwd we have to show its methods and service description(wsdl).
What do you mean by directing?
What is the difference between TypeOf, GetType and what are the uses of TypeOf, GetType.
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)