Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use reflection. For example, if all of the myList_ variables are private instance variables of a class (like the Form that this even handler is defined in), then you could do something like this:</p> <pre><code>FieldInfo[] fields = MyForm.GetType().GetFields( BindingFlags.NonPublic | BindingFlags.Instance); </code></pre> <p>You'd then have to look for one with a matching name. I think there's a method to lookup a member by name, but I'm not remembering it right now. See <a href="http://msdn.microsoft.com/en-us/library/System.Type_methods.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/System.Type_methods.aspx</a> for more options.</p> <p>A more conventional approach would be to create a Dictionary that maps the name to the list object. You could populate this dictionary when the form loads then just call something like:</p> <pre><code>myFonction(dictionary["myList_" + myCombo.SelectedItem.ToString()]); </code></pre> <p>Of course, you don't have to populate the dictionary by hand: you could use reflection (like I showed above) to fill the dictionary at run-time. Then when you add a new list, you don't have to remember to add it to the dictionary. You could also use the same method to populate the combo box.</p> <p>Note: I am not suggesting that I necessarily condone what you are doing as a good design principle. That doesn't mean it can't be done. Or done well. Or be reasonable.</p> <p>EDIT: I just noticed the <strong>ref</strong> in your call (I copied and pasted your code). I can't see any reason to pass the list by reference. In any case, you can't pass it by reference if you are getting it from a dictionary -- again, why are you passing by reference?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload