Switch or IndexOf

No Comments

Which one outperforms other ?

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


switch (searchedValue)
case "a":
case "b":
case "c":
found = true;
found = false;

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.

Categories: Development Tags: Etiketler: