Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

What?s different about switch statements in C#?

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


Please Help Members By Posting Answers For Below Questions

Explain how do I get deterministic finalization in c#?

885


What is the difference between a constant and a static readonly field?

940


Explain the difference between private and shared assembly?

826


What is task parallel library?

959


How do you pronounce c#?

841


What is the value which is accepted by all data types ?

943


Can an interface extend a class c#?

895


How big is an int in c#?

920


Is c# pass by reference?

840


What is append in c#?

797


Why is lazy loading?

827


What is as keyword in c#?

930


What is static variable in c#?

897


Explane each and every methods of nterface Queue? Explain About performance issues on retrieving records

988


Why do we use static class in c#?

853