.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Articles >> C# >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Switch Statement

Posted By:Shashi Ray       Posted Date: February 19, 2009    Points: 15    Category: C#    URL: http://www.dotnetspark.com  

Switch Statement


The switch statement allows you to provide a list of possible values for a variable and code to execute if each is true. In C#, however, the variable you compare in a switch statement must be either an integer or a character type and must be enclosed in parentheses:


switch ( j )


case 12:




case 13:

System.out.println("1 PM"); "




System.out.println("some other time...");



Note particularly that a break statement must follow each case in the switch statement. This is very important, as it says "go to the end of the switch statement." If you leave out the break statement, the code in the next case statement is executed as well.


Shashi Ray

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend