В чем ошибка? с#
Данный код должен во втором текстбоксе выводить наибольшее количество повторяющихся элементов из dataGridView прим.
есть массив 1 2 4 7 9 5 2 2 4
в результате в textBox2 должно выводиться число 3, т.к. число число 2 повторяется больше остальных, а именно 3 раза, вместо этого в textBox2 выводится количество элементов массива.
Как исправить эту ошибку?
namespace WinFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int n = Convert.ToInt16(textBox1.Text);
int[] a = new int[n];
var column1 = new DataGridViewColumn();
column1.HeaderText = "ELEMENTI";
column1.CellTemplate = new DataGridViewTextBoxCell();
dataGridView1.Columns.Add(column1);
Random rnd = new Random();
for (int i = 0; i < n; i++)
{
a[i] = rnd.Next(10);
dataGridView1.Rows.Add();
dataGridView1[0, i].Value = a[i];
}
string[] b = new string[dataGridView1.RowCount];
for (int i = 0; i <= dataGridView1.RowCount-2; i++)
{
b[i] = dataGridView1[0, i].Value.ToString();
}
int o = 0;
int date = n;
int[] arra = new int[date];
int empare = 0;
for (int g = 0; g < 11; g++)
{
empare = 0;
for (int q = 0; q <= date-1; q++)
{
if (arra[q] == g)
{
empare++;
}
}
if (empare >= 2)
{
while (empare > o)
{
o++;
}
}
textBox2.Text = o.ToString();
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}
Источник: Stack Overflow на русском