Powered by Blogger.

Saturday, March 8, 2014

switch statement in C#.Net

In this article we will discuss about switch statment in C#.Net.
Also you can check out:

- List all Stored Procedure Created and Modified in Last N Days in SQL Server 2008

- Extension method in MVC

- Bind gridview using datareader in asp.net

Beginers can check out some interview questions.

- switch statement that you can use to evaluate a single variable or expression for multiple possible values.

- switch statement supports only an integer-based data type, a bool, a char, a string, or a value from an enumeration. Other data types aren't supported.

- Example
string website =string.Empty;

switch (webSiteCode)
case 1:
website = "Fewlines4Biju.com";
case 2:
website = "EnjoySharePoint.com";
website = "AspDotNetHelp.com";

- Each case statement should be end with a break; statement else compiler will give error. But if a case statement does not contain any code then it may not contain a break statement.