title: Getting all variables inside a struct of unknown size (C#)
body: <p>I have a project in which I have to get all the variables from a struct in a different class and add all their names to a combo box in a form. My primary issue at the moment is iterating through the struct in a way that I can add each variable individually to the combo box. I tried doing this:</p>
  
  <pre><code>        msgVars vars = new msgVars();
          foreach (object obj in vars)
          {
              comboBox1.Items.Add(GetName(obj));
          }
  </code></pre>
  
  <p>but as you probably know, you can't iterate through a struct that way. Is there any way I can do this without hardcoding the variables in?</p>
  
  <p>Also, for reference, this is the GetName function:</p>
  
  <pre><code>static string GetName&lt;T&gt;(T item) where T : struct
  {
      var properties = typeof(T).GetProperties();
      if (properties.Length == 1)
      {
          return properties[0].Name;
      }
      else
      {
          return null;
      }
  }
  </code></pre>