【发布时间】:2016-09-21 07:44:50
【问题描述】:
我需要将平均值从<List> 写入textBox1 的代码。单击button1 2 次textBox1 应该给我来自rotorSpeed 的ElapsedMilliseconds 平均值。
Stopwatch rotorSpeed = new Stopwatch();
List<double> list = new List<double>();
double av;
private void button1_Click(object sender, EventArgs e)
{
int i = 0;
i++;
do
{
if (rotorSpeed.IsRunning)
{
rotorSpeed.Stop();
list.Add(rotorSpeed.ElapsedMilliseconds);
continue;
}
else
{
rotorSpeed.Reset();
rotorSpeed.Start();
}
} while (i == 2);
av = list.Average();
textBox1.Text = av.ToString();
}
}
【问题讨论】:
-
你的问题缺少问题...
-
虽然 (i >= 2) 在这里永远不会是真的,你想做什么?
-
@sachin 是的,我 == 2 对不起
-
@rltcounter221 即使 i==2 永远不会是真的,你永远不会在循环中增加计数器。
-
@sachin 这就是我需要你帮助的原因。我想要的是点击 2 次按钮,我得到文本框的毫秒平均值