title: System.IndexOutOfRangeException: 'Index was outside the bounds of the array.' C#
body: <p>I am currently working on a project where I connect an arduino uno to a windows form and display the temperature in it using serial communication.
  However I got this weird error every time I compiled my app</p>
  
  <blockquote>
    <p><strong>System.IndexOutOfRangeException:</strong> 'Index was outside the bounds of the array. </p>
  </blockquote>
  
  <p>I have declared my string array correctly. Can anyone help me to overcome this issue?</p>
  
  <p><img src="https://i.stack.imgur.com/bbgrj.png" alt="SERIAL COM ARDUINO (IMAGE)"></p>
  
  <pre><code>using System;
  using System.Windows.Forms;
  using System.Threading.Tasks;
  
  namespace WindowsFormsApp1
  {
      public partial class Form1 : Form
      {
          public Form1()
          {
              InitializeComponent();
              serialPort1.Open();
          }
  
          public String[] towTemp = new string[1];
          public Task Tempdisplay()
              {
              //timer1.Start();
              return Task.Factory.StartNew(() =&gt;
              {
                  try
                  {
                      String tempFromArduino = serialPort1.ReadLine().ToString();
                      towTemp = tempFromArduino.Split(',');
                      CheckForIllegalCrossThreadCalls = false;
                      if (float.TryParse(towTemp[0], out float result1))
                      {
                      result1 = (float)(Math.Round(Convert.ToDecimal(result1), 1));
                      label2.Text = result1.ToString();
                      aGauge1.Value = result1;
                      }
                      else
                      {
                          return;
                      }
                      if (float.TryParse(towTemp[1], out float result2))
                      {
                      result2 = (float)(Math.Round(Convert.ToDecimal(result2), 1));
                      label3.Text = result2.ToString();
                      aGauge2.Value = result2;
                      }
                      else
                      {
                          return;
                      }
  
  
  
  
                  }
                  catch (Exception err)
                  {
                     MessageBox.Show(err.ToString());
                  }
              });
              }
  
          private async void timer1_Tick(object sender, EventArgs e)
          {
  
              timer1.Interval = 1000;
             await Tempdisplay();
  
  
  
          }
  
          private void Form1_FormClosed(object sender, FormClosedEventArgs e)
          {
  
              timer1.Stop();
          }
  
          private void button1_Click(object sender, EventArgs e)
          {
  
              timer1.Start();
          }
      }
  }
  </code></pre>