+ 1

How can use switch with array in C#

23rd Apr 2017, 6:19 PM
ALAMOUDI, WAEL MAKKI S
ALAMOUDI, WAEL MAKKI S - avatar
3 ответов
+ 12
I don't think so. Switch is mostly used with int or char
23rd Apr 2017, 6:28 PM
Sachin Artani
Sachin Artani - avatar
+ 1
u cant use switch with array , according to MSDN switch can only used with bool , char , string , integral and other corresponding nullable type and enum but u can use one element from the array with switch
23rd Apr 2017, 10:16 PM
givara
givara - avatar
+ 1
int[] a = new int[] { 1, 2, 3, 5 }; switch (a[1]) { case 1:Console.WriteLine("1"); break; }
23rd Apr 2017, 10:17 PM
givara
givara - avatar