При выводе min / max / среднего значения выводятся 0-ли
Вот код:
class one //основной для роботы с массивами символов
{
public double Max;
public double Min;
public double[] SortArr = new double[10];
}
public double[] BubbleSort(double[] array)
{
double temp;
for (int i = 0; i < array.Length; i++)
{
for (int j = 0; j < array.Length - 1 - i; j++)
{
if (array[i] > array[j + 1])
{
temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
}
}
}
for (int i = 0; i < array.Length; i++)
{
richTextBox1.Text += (array[i].ToString() + " ");
}
return array;
}
public double method(double min, double max)
{
textBox1.Text += ((string)"Min = " + min + " " + "Max = " + max);
return 0;
}
public double BubbleSortOut(double[] SortOut)
{
for (int i = 0; i < SortOut.Length; i++)
{
richTextBox1.Text += (SortOut[i].ToString() + " ");
}
return 0;
}
private void button1_Click(object sender, EventArgs e)
{
int SumCell = 0;
textBox1.Visible = false;
one One = new one();
bool indic = true;
var _listOfTrad = new List<Double>();
for (int a = 0; a < dataGridView1.Rows.Count - 1; a++)
{
if (dataGridView1.Rows[a].Cells[0].Value != null)
{
_listOfTrad.Add(Convert.ToDouble(dataGridView1[0, a].Value));
}
else
{
MessageBox.Show("Not enough values!");
indic = false;
}
}
One.Min = _listOfTrad.Min();
One.Max = _listOfTrad.Max();
_listOfTrad.Average();
for (int i = 0; i < dataGridView1.RowCount; i++) //кол-значний в dataGrid
{
for (int y = 0; y < dataGridView1.ColumnCount; y++)
{
if (dataGridView1[y, i].Value != null)
{
SumCell = SumCell + 1;
}
}
}
double[] array = new double[SumCell];
_listOfTrad.CopyTo(array);
double[] SortArray = new double[SumCell];
SortArray = BubbleSort(array);
SortArray.CopyTo(One.SortArr, 0);
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Visible = true;
one One = new one();
method(One.Min, One.Max);
}
private void button3_Click(object sender, EventArgs e)
{
textBox1.Visible = true;
one One = new one();
BubbleSortOut(One.SortArr);
}
private void button4_Click(object sender, EventArgs e)
{
textBox1.Visible = true;
one One = new one();
textBox1.Text += (One.SortArr.Average());
}
Источник: Stack Overflow на русском