What?s different about switch statements in C#?

Answers were Sorted based on User's Feedback



What?s different about switch statements in C#?..

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?s different about switch statements in C#?..

Answer / swapna

No fall-throughs allowed.

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More C Sharp Interview Questions

Explain the different ways a method can be overloaded?

0 Answers  


how can i display crystalreport in button click? am working with VS2005

1 Answers  


What are modifiers in c#?

0 Answers  


How can you prevent escaping on backslashes in C# with string definitions?

0 Answers   Siebel,


I have a very important query in my mind. Please help me regarding this. I don't have any real time exp in .net. But I have a knowledge it .net. I got an offer from an MNC company as a software developer has I had kept 2 years of fake exp. Even though for this job I had worked hard to crack interview for about an year. So, I would like to know how difficult it will be for working in real time as I don't have real time exp. Please tell me as soon as possible bcoz I need to join by next month. Can i sustain over there for a longer time or not. And also let me know how to work pressure will be over there. Please help me regarding this. I'm getting tension thinking about it. Thank you.

1 Answers  






Explain the difference between the system.array.copyto() and system.array.clone()?

0 Answers  


Explain the Abstract class in c#.net

0 Answers  


What is dynamic in c#?

0 Answers  


What is string programming language?

0 Answers  


What is sealed class in c#?

0 Answers  


What is a method c#?

0 Answers  


What do you mean by generic class in c#?

0 Answers  


Categories