i made this UI it works fine , but i cant make it with the OUT parameter in the arrayMath method

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);

            arrayMath(myArray);
            displayArray(myArray);
            
          
        }
        public void arrayMath(double [] myArray)
        {
            double sum = myArray.Sum();
            double avg = myArray.Average();
            label2.Text = "The Sum is: " + sum + "\n" + "The Average is: " + avg + "\n";
          

        }
        public void displayArray(double[] myArray)
        {
            foreach (double d in myArray)
            {
              
              label2.Text += "\t\t " +d.ToString();
            }
        }
       

    }
}

Recommended Answers

All 8 Replies

You mean something like this?

public void arrayMath(double[] myArray, out double avg)
        {
            avg = myArray.Average();
        }

but when i change it to this : arrayMath(myArray, out avg, out sum);

i am getting some errors

Specify which errors.
This gives no errors:

public void arrayMath(double[] myArray, out double avg, out double sum)
        {
            avg = myArray.Average();
            sum = myArray.Sum();
        }

the bold line gives me the error

[B]arrayMath(myArray, out double, out double);[/B]
            displayArray(myArray);
          //  label2.Text = "The Sum is: " + sum + "\n" + "The Average is: " + avg + "\n";
          
        }
        public void arrayMath(double [] myArray, out double sum, out double avg)
        {
             sum = myArray.Sum();
             avg = myArray.Average();
            label2.Text = "The Sum is: " + sum + "\n" + "The Average is: " + avg + "\n";

the bold line gives me the error

        arrayMath(myArray, out double, out double);
        displayArray(myArray);
      //  label2.Text = "The Sum is: " + sum + "\n" + "The Average is: " + avg + "\n";

    }
    public void arrayMath(double [] myArray, out double sum, out double avg)
    {
         sum = myArray.Sum();
         avg = myArray.Average();
        label2.Text = "The Sum is: " + sum + "\n" + "The Average is: " + avg + "\n";

Sorry for the late reply, internet problems here.
My provider is installing Fibernet(speed of light I hope :S ) all over my country I guess.
Instead of arrayMath(myArray, out double, out double);
you should try something like

double MyAvg = 0.0;
double MySum= 0.0;
arrayMath(myArray, out MyAvg, out MySum);

My compliments to the Programmer !!!!!!!!

You did the programming! I just gave sugestions, but thanks anyway :)
Could you mark this thread as solved?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.