title: Concatenate variable in variable name
body: <p>I have a list of variable in ASP.NET (C#) that I'm trying to loop through without writing dozens of If statements. What I was hoping to do is just reference each of them with a variable and append it to the variable name. So something like the following:</p>
  
  <pre><code>string _id1 = Id1CheckBox.Checke.ToString();
  string _id2 = Id2CheckBox.Checke.ToString();
  string _id3 = Id3CheckBox.Checke.ToString();
  
  int x = 1;
  
  while (x &lt; 20)
  {
      if ("_id&amp;" + x == "True")
      {
          _id + x = x.ToString();
      }
      else
      {
          _id + x = 0;
      }
      x++;
  }
  </code></pre>
  
  <p>The logic behind what I'm trying to do is I have several checkboxes on a form, Id1CheckBox, Id2CheckBox, Id3CheckBox, etc. I need get these values as strings so I can pass them as parameters in a SQL query. So basically If Id1CheckBox = true then _id1 = 1. If Id2CheckBox = true then _id2 = 2. If any are false then I would want something like If Id3CheckBox = false then _id3 = 0. Is this possible or will I just need to write several If statements instead of using a loop?</p>