title: c# user interface elements in array
body: <p>I'm pretty new to C# and got a small project to extend. The code is a mess and I'm trying to improve it somehow but seem to reach some limits of the language.</p>
  
  <p>Basically I'm reading sensor values from up to four sensors and show some of them in labels. Since the loop is always the same I wanted to iterate instead of rewriting the same code four times with just different GUI elements to store values in. My research showed me that I could put my labels in an array manually but the Visual Studio editor will overwrite this each time I change anything in the GUI. So my approach was to create an array of references to the elements like</p>
  
  <pre><code>ref GroupBox[] gbChannel;
  </code></pre>
  
  <p>but it's not possible in C#. If I try to assign it directly </p>
  
  <pre><code>gbChannel[0] = gbChannel0;
  </code></pre>
  
  <p>C# informs me that I have to check if the object is null before doing this. Anyways,</p>
  
  <pre><code>if(gbChannel1!=null) gbChannel[0] = gbChannel0;
  </code></pre>
  
  <p>leads to the same result.</p>
  
  <p>Is there any convinient way to achieve what I want to do?</p>