Hi experts,

I'm total newbie with C# and I ran into challenge that must be simple to solve. I have defined several 2-dimensional arrays, named like Par1001, Par1002, Par1003 and so on. And now the challenge, how can I use a string variable to replace the 'Case' structure with function? Attached code works, it populates the combobox with different values, depending of the value of the string 'ParameterNumber'.

There will be around 30-40 arrays, so the way it is now build isn't the easiest or the most practical way.

Thanks in advance!

Recommended Answers

All 2 Replies

Use a dictionary<String,WhateverYourArrayIs> to hold all the values, and use the name to look them up in the dictionary.

yeah, or any other type of collection that supports generics, then use LINQ syntax to quickly search though your collection, and apply your case depending on the results you get from your query.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.