jeudi 27 avril 2017

Getting the name of the variable in a foreach loop

I am trying to get the name of the variables from a List that represents a Value of the dictionary so that i can fill a combo box.So far i have tried using nameof method but i cant't get the name.
In My example i would like to fill the combobox with param1,param2,param3

The const variables are in another class Constants.

        public const string param1 = "a";
        public const string param2 = "b";
        public const string param3 = "c";
        public const string d = "d";
        public const string e = "e";
        public const string f = "f";

The dictionary of lists containing constants

  public static Dictionary<string, List<string>> formIdDict = new Dictionary<string, List<string>>
            {
                {singleParamFo,new List<string> {param1,param2,param3 } },
                {PIDFo,new List<string> {d,e,f } }
            };

The troublesome foreach

public SingleParamForm()
        {
            InitializeComponent();
            foreach (var t in Constants.formIdDict[Constants.singleParamFo])
                singleParamCombo.Items.Add(nameof(t));
        }

What type should i specify in the foreach since i cant use something like

foreach(nameof(var t) in ....)





Aucun commentaire:

Enregistrer un commentaire