I am writing a piece of code that to work would require an extensive amount of if/then statements. In order to eliminate the need for writing line upon line of if/then statements can I use a dictionary or a list? If so can someone direct me to a good web resource or show an instance where they have done it before?
Edit
Clarification: I have six inputs, each are to be combo boxes with a group of selections. Below is a detail of the inputs and the selections.
(Amps) 1:1 – 1:12 (12 different selections)
(Cable Size) 2:1 – 2:13 (13 different selections) Certain items in this list will be excluded by the selection of the first input.
(Cable Type) 3:1 – 3:2 (2 different selections)
(Temp Rating) 4:1 – 4:3 (3 different selections)
(System Type) 5:1 – 5:2 (2 different selections)
(Conduit Type) 6:1 – 6:2 (2 different selections)
From the above input will come two outputs which will appear in two text boxes.
(Cable Qty) 7:1 – 7:16 (16 different outputs)
(Conduit Size) 8:1 – 8:8 (8 different outputs)
I hope this serves to help and not hinder.
It looks like you’re trying to map each combination of the 6 inputs (12 * 13 * 2 * 3 * 2 * 2 possibilities) to one of the (16 * 8) outputs. If that’s the case, you’ll still have a lot of typing to do – but moving to a collection will allow you to easily externalize the mapping. I would guess that this would probably be best suited for a database table:
You’d put a primary key on the 6 input columns, and then just do a simple SELECT:
To do this in quick and dirty code, arrays would work:
It doesn’t save you much typing – though you could use for loops and the like to populate the mappings if there’s some sort of logic to it – but it’s a hell of a lot more readable than 6 pages of if statements (I’d probably region off or partial class loading the mappings).