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.
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
ref GroupBox[] gbChannel;
but it's not possible in C#. If I try to assign it directly
gbChannel[0] = gbChannel0;
C# informs me that I have to check if the object is null before doing this. Anyways,
if(gbChannel1!=null) gbChannel[0] = gbChannel0;
leads to the same result.
Is there any convinient way to achieve what I want to do?