Switch or IndexOf

Which one outperforms other ?

string[] array = new string[] {"a","b","c"};
found = (Array.IndexOf<string>(array, searchedValue) >= 0);

Or

switch (searchedValue)
{
case "a":
case "b":
case "c":
found = true;
break;
default:
found = false;
break;
}

Actually for me it is a matter of design. The first array approach may be suitable for group of strings representing a same subject such as names of employees, model of cars, etc.. but the second one can be a mixed typed. On the other our lead developer (Ertan Tike) approved me execution time of the second one outperforms 7-8 times the first one.

Comments ( 0 )