
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
How to use strings in switch statement in C#
A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each switch case.
Example
Here is an example to use strings in a switch statement −
using System; public class Demo { public static void Main(String[] args){ string grades = "A1"; switch (grades) { case "A1": Console.WriteLine("Very good!"); break; case "A2": Console.WriteLine("Good!"); break; case "B1": Console.WriteLine("Satisfactory!"); break; default: Console.WriteLine("Invalid!"); break; } Console.WriteLine("Grade = "+grades); } }
Output
This will produce the following output −
Very good! Grade = A1
- Related Articles
- Can we use Switch statement with Strings in java?
- Java Program to Implement switch statement on strings
- Golang program to implement switch statement on a strings
- Switch case statement in C
- How to use PowerShell Break statement with the Switch command?
- What is a switch case statement in Java and how to use it?
- Explain switch statement in C language
- How to implement switch-case statement in Kotlin?
- Switch Statement in Java
- How to use the return statement in C#?
- Can you use a switch statement around an enum in Java?
- How do we use nested switch statements in C#?
- How to define a switch statement in JShell in Java 9?
- How to write a switch statement in a JSP page?
- Java switch statement

Advertisements