所以我有一个工资列表框。一个按钮,如果点击,则显示高于平均工资金额的工资数量,以及低于平均工资金额的数字。但是,我不能为我的生活弄清楚如何形成这个循环,返回平均值以下的数字。工资金额。以下是我到目前为止的情况:
double[] employeeSalary = new double[7] { 8500.50, 7005.99, 9123.00, 100123.50, 6550.00, 8123.90, 7500.95 };
public Form2()
{
InitializeComponent();
listBox1.DataSource = employeeSalary;
}
private void button3_Click(object sender, EventArgs e)
{
double avgSalary;
avgSalary = employeeSalary.Average();
for (int i = 0; i < employeeSalary.Length; i++)
{
}
}
答案 0 :(得分:4)
您已经使用过LinQ,您也可以将其用于其他任务:
var avgSalary = employeeSalary.Average();
var aboveAverageCount = employeeSalary.Count(x => x > avgSalary);
var belowAverageCount = employeeSalary.Count(x => x < avgSalary);