Yes of course, we can use strings in a switch statements. String type and integer type both can be used in switch statement. See the following example:
class StringWithSwitch { public static void Main() { string[] strArr = { "Delhi", "Paris", "Tokya" }; foreach (string str in strArr) { switch (str) { case "Delhi": Console.WriteLine("Delhi is capital of India"); break; case "Paris": Console.WriteLine("Paris is capital of France"); break; case "Tokyo": Console.WriteLine("Tokyo is capital of Japan"); break; } } } }
Output will be :
Delhi is capital of India
Paris is capital of France
Tokyo is capital of Japan