How To Use Switch Statement to check if Values from Excel Column belongs to one Liste?

Have a look on following approach:

Using a dictionary with its key for the different lists

 dictLists
 Dictionary<string, List<string>>(3) { { "Letters", List<string>(5) { "A", "B", "C", "C", "D" } }, { "Greek", List<string>(4) { "Alpha", "Beta", "Gama", "Theta" } }, { "Items", List<string>(3) { "Item1", "Item2", "Item3" } } }
 strCheck
 "Alpha Bank"
 arrMatchKeys = dictLists.Keys.Where(Function (x) dictLists(x).Intersect(strCheck.Split(" "c)).Count > 0).toArray
 string[1] { "Greek" }
 arrMatchKeys
 string[1] { "Greek" }

for sure, The LINQ statement can also be decomposed to essential activities. The approach will work dynamicly over all contained lists within the dictionary and requires no change e.g. when additional lists are added to the dictionary.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.