C# | How to use strings in switch statement Last Updated : 21 Feb, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report The switch statement is a multiway branch statement. It provides an easy way to forward execution to different parts of code based on the value of the expression. String is the only non-integer type which can be used in switch statement. Important points: Switching on strings can be more costly in term of execution than switching on primitive data types. Therefore, it is good to switch on strings only in cases in which the controlling data is already in string form.The comparison perform between String objects in switch statements is case sensitive.You must use break statements in switch case. Example 1: CSharp // C# program to illustrate how to use // a string in switch statement using System; class GFG { // Main Method static public void Main() { string str = "one"; // passing string "str" in // switch statement switch (str) { case "one": Console.WriteLine("It is 1"); break; case "two": Console.WriteLine("It is 2"); break; default: Console.WriteLine("Nothing"); } } } Output: It is 1 Example 2: CSharp // C# program to illustrate how to use // a string in switch statement using System; class GFG { // Main Method static public void Main() { string subject = "C#"; // passing string "subject" in // switch statement switch (subject) { case "Java": Console.WriteLine("Subject is Java"); break; case "C++": Console.WriteLine("Subject is C++"); break; default: Console.WriteLine("Subject is C#"); } } } Output: Subject is C# Comment More infoAdvertise with us Next Article C# | How to use strings in switch statement A ankita_saini Follow Improve Article Tags : C# CSharp-string CSharp-ControlFlow Similar Reads C# Switch Statement In C#, Switch statement is a multiway branch statement. It provides an efficient way to transfer the execution to different parts of a code based on the value of the expression. The switch expression is of integer type such as int, char, byte, or short, or of an enumeration type, or of string type. 4 min read Switch Expression in C# 8.0 The switch statement is a multiway branch statement. It provides an easy way to forward execution to different parts of code based on the value of the expression. So, with switch statement you always use some repetitive case and break keywords and also use default statement as shown in the below exa 2 min read Switch Statement in C C switch statement is a conditional statement that allows you to execute different code blocks based on the value of a variable or an expression. It is often used in place of if-else ladder when there are multiple conditions.Example:C#include <stdio.h> int main() { // Switch variable int var = 5 min read Interesting facts about switch statement in C Prerequisite - Switch Statement in C Switch is a control statement that allows a value to change control of execution. C // Following is a simple program to demonstrate syntax of switch. #include <stdio.h> int main() { int x = 2; switch (x) { case 1: printf("Choice is 1"); break; cas 3 min read Difference Between if-else and switch in C In C programming both switch statements and if-else statements are used to perform decision-making and control the flow of the program according to predefined conditions. In this article, we will discuss the differences between the if-else and switch statements. switch StatementA control flow statem 4 min read Like