Does switch take interger values for case ? Like case :1, Case:"one" | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Does switch take interger values for case ? Like case :1, Case:"one"

28th Jan 2018, 6:34 PM
Avtar Singh
Avtar Singh - avatar
3 Answers
+ 6
case 1 : is integer no doubt. but case "one" : is string. if its Java then both can be given and the vlaue will be checked with the one in switch statement.
28th Jan 2018, 6:46 PM
cHiRaG GhOsH
cHiRaG GhOsH - avatar
+ 1
Works in C# like this int myVar = 2; switch(myVar){ case 1: Console.WriteLine(1); break; case 2: Console.WriteLine(2); break; };
28th Jan 2018, 6:48 PM
Denis Jay
+ 1
thanks
28th Jan 2018, 6:48 PM
Avtar Singh
Avtar Singh - avatar