我有一个dataGridView,我有列时间 我需要在这个dataGridView中获得所有时间的平均值 这是我的代码,以获得平均值,但它不起作用
public void avghold()
{
double[] AVG_HLOD = new double[dataGridView1.Rows.Count];
AVG_HLOD = (from DataGridViewRow row in dataGridView1.Rows
where row.Cells["Avg_Hold"].FormattedValue.ToString()
!= string.Empty
select Convert.ToDouble(row.Cells["Avg_Hold"].FormattedValue)).ToArray();
double Avghold = AVG_HLOD.Average();
label17.Text = AVG_HLOD.Average().ToS
}
and this the image from the column
单击运行时显示此错误 Please click here
谢谢大家,
答案 0 :(得分:0)
试试这个。
double avg = yourDataGridView.Rows.Cast<DataGridViewRow>()
.AsEnumerable()
.Average(x => int.Parse(x.Cells["Avg_Hold"].Value.ToString()));