Posted by : Anwar Hossain
Category : asp.net c # basic tutorial

C Sharp switch case statement Example

Dear viewer’s in this tutorial I will show simple switch-case statement so that you can understand about switch...case statement easily in c#. Switch statement is known as control statement. A switch statement includes one or more switch section each switch section contains one or more case labels followed by one or more statements. The first example is simple switch...case statement that has five switch sections. Each switch section has one case label, such as case 80, as case 70, case 60, case 50, and default. Switch statement default case is optional.

C Sharp switch case statement Example

C # switch statement Example

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace switchcaseStatement

{

    class Program

    {

        static void Main(string[] args)

        {

 

            /*  realtime this value are given by user to see result */

 

            int Number = 80;

 

            switch (Number)

            {

                case 80:

                    /* case label one*/

                    Console.WriteLine("\n You got A + grade");

                    break;

              

                case 70:

                    /* case label two*/

                    Console.WriteLine("You have got A grade");

                    break;

 

                case 60:

                    /* case label three*/

                    Console.WriteLine("You have got A - grad");

                    break;

 

                case 50:

                    /* case label four*/

                    Console.WriteLine("You have got B - grad");

                    break;

 

                default:

                    Console.WriteLine("Invalid grade");

                    break;

            }

 

            Console.WriteLine("\n Your grade is  {0}", Number.ToString());

 

            Console.ReadLine();

 

    

           

 

          

        }

    }

}

Out Put

switch-case-in-c-sharp



Realted Article Headline

How to find odd number in c #
How to generate random number in c #
Nested For Loop Example in C Sharp
Store C sharp reference type in a List C#
Find number of items in a List C#
Concept about C # List
Custom Time formatting example C #
Custom Date formatting example C #
String Format Example using ASP.Net C#
Simple enum example in C Sharp
Nested switch-case statement example in C #
Combined switch...case statement example in C #
C Sharp switch case statement Example
C# SUM ArrayList Element Example
C# String Class Methods Example
C Sharp String Class Properties and Methods
C Sharp String Class Example
How to join two ArrayList collections in C#.
How to Use C Sharp Math Class
C Sharp ArrayList Property and Method
C Sharp ArrayList Example
C Sharp Arrays Example
C Sharp Logical operator Example
C Sharp Relational operators
C Sharp Arithmetic operators Example
C Sharp Common Assignment Operator
Simple for loop example in c sharp

Article Category

How to create asp.net control dynamically
Learn HTML for beginner
DataList example in C Sharp
Mail sending in asp.net c#
State Management in ASP C #
Basic sql tutorial for Beginner
DataTable example in ASP.Net C#
How to use LINQ in ASP.NET C#
asp.net c # basic tutorial
How to use ajax toolkit in asp.net C#
How to use different types of validation control using asp.net c#
How to use grid view in asp.net c#
Protected by Copyscape Online Plagiarism Detection