i am getting this error and i dont know how to get rid of it
its in GUI BTW


Error 1 'ArrayManagementGUI.Form1.displayArray(double[])': not all code paths return a value F:\CSIS115c\ArrayManagementGUI\ArrayManagementGUI\Form1.cs 47 24 ArrayManagementGUI

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ArrayManagementGUI
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }



        double[] myArray = new double[8];
        private void button1_Click(object sender, EventArgs e)
        {

            myArray[0] = Convert.ToDouble(textBox1.Text);
            myArray[1] = Convert.ToDouble(textBox2.Text);
            myArray[2] = Convert.ToDouble(textBox3.Text);
            myArray[3] = Convert.ToDouble(textBox4.Text);
            myArray[4] = Convert.ToDouble(textBox5.Text);
            myArray[5] = Convert.ToDouble(textBox6.Text);
            myArray[6] = Convert.ToDouble(textBox7.Text);
            myArray[7] = Convert.ToDouble(textBox8.Text);


            label2.Text = "The Sum is {0} {0}\n" + arrayMath(myArray).ToString();
            label2.Text += "" + displayArray(myArray).ToString();

        }

    
        private double arrayMath(double[] myArray)
        {
            double sum = myArray.Sum();
            double avg = myArray.Average();
            return sum;
        }
        private double displayArray(double[] myArray)
        {
            foreach (int i in myArray)

                return displayArray(myArray);
        }
        
    }
}

The return statement on line 51 forms part of the foreach statement on line 49.
Use brases and you'll see it.
What more, you are calling displayArray recursivly. This method would go on forever.
BTW. it is UI not GUI. :angry:

Try something like this:

private void displayArray(double[] myArray) 
        {
            foreach (double d in myArray)
            {
                MyLabel.Text += d.ToString();
            }
        }
This article has been dead for over six months. Start a new discussion instead.