---
title: "Define Switch statement."  
description: "Define Switch statement."  
author: "Anonymous User"  
published: 2020-01-21  
updated: 2020-01-21  
canonical: https://www.mindstick.com/forum/155712/define-switch-statement  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Define Switch statement.

[Please tell me](https://www.mindstick.com/forum/33900/please-tell-me-what-are-the-technique-to-content-optimization) what is [switch statement](https://www.mindstick.com/forum/55166/how-to-use-the-switch-statement-in-java) with its [flow](https://answers.mindstick.com/qa/105072/how-to-trade-with-the-money-flow-index) [chart](https://www.mindstick.com/articles/1509/show-google-analytics-data-in-chart-in-asp-dot-net-mvc) and with example.

## Replies

### Reply by Nishi Tiwari

**[Switch](https://www.mindstick.com/blog/104495/switch-bringing-new-advancements-in-the-education-management-system) is a selection statement** to execute a single statement from a list of multiple statement based on pattern match with the expression.

The switch expression is used with integer type such as int, char, byte, or short, an enumeration type, or of string type. The expression is checked for various cases and the one match is executed.

Switch can be used in place of if-else statement to provide better readability of code.

## Syntax

```
switch(expresion)
{ case value1:
//statement to execute
break;
case value2:
//statement to execute
break;
…….
…….
default:
//statement to execute if no case matches
break;
}
```

## Why do we use Switch Statements instead of if-else statements?

We generally use a switch statement instead of if-else statements because **[if-else statement](https://www.mindstick.com/forum/155711/what-is-if-else-statement-in-c-sharp)** works only for a small number of logical evaluations of a value. If we use if-else statement for a larger number of possible conditions then, it will take more time to write and also become difficult to read.

```
// C# program to illustrate
// switch case statement
using System;

public class GFG {

    // Main Method
    public static void Main(String[] args)
    {
        int nitem = 5;
        switch (nitem) {

        case 1:
            Console.WriteLine("case 1");
            break;

        case 5:
            Console.WriteLine("case 5");
            break;

        case 9:
            Console.WriteLine("case 9");
            break;

        default:
            Console.WriteLine("No match found");
            break;
        }
    }
}
```

![Define Switch statement.](https://www.mindstick.com/mindstickforums/166f2d51-020e-4db5-9210-b0a4ae920ce0/images/f4360282-c4d8-4ce0-baf4-b048158073ed.jpeg)

![Define Switch statement.](https://www.mindstick.com/mindstickforums/166f2d51-020e-4db5-9210-b0a4ae920ce0/images/fdffd340-df41-40a1-8e34-2971c5897bf6.png)\


---

Original Source: https://www.mindstick.com/forum/155712/define-switch-statement

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
