Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 7天平均病例表_C# - Fatal编程技术网

C# 7天平均病例表

C# 7天平均病例表,c#,C#,我是一个新手,老实说,我为此奋斗了很多。我试图计算从texbox到listbox的所有条目,然后除以7,并在输出标签中显示平均值。我无法显示案例平均值。代码如下: public partial class formAverageWeeklyCases : Form { int SEVEN = 7; public formAverageWeeklyCases() { InitializeComponent(); } private vo

我是一个新手,老实说,我为此奋斗了很多。我试图计算从texbox到listbox的所有条目,然后除以7,并在输出标签中显示平均值。我无法显示案例平均值。代码如下:

public partial class formAverageWeeklyCases : Form
{ 
    int SEVEN = 7;

    public formAverageWeeklyCases()
    {
        InitializeComponent();
    }

    private void buttonExit_Click(object sender, EventArgs e)
    {
        Application.Exit();
    }

    private void buttonEnter_Click(object sender, EventArgs e)
    {
        if (textBoxCaseEntry.Text.Trim().Length >= 1)
        {
            listBoxDailyCases.Items.Add(textBoxCaseEntry.Text.Trim());
            textBoxCaseEntry.Text = string.Empty;
            textBoxCaseEntry.Focus();
        }
        else 
        {
            MessageBox.Show("The number entered does not appear to be valid");
            textBoxCaseEntry.Text = string.Empty;
            textBoxCaseEntry.Focus();
        }
    }

    private void buttonReset_Click(object sender, EventArgs e)
    {
        textBoxCaseEntry.Text = string.Empty;
        listBoxDailyCases.Items.Clear();
        labelOutputDailyAverage.Text = string.Empty;
    }

    private void textBoxAverageWeeklyCases_TextChanged(object sender, EventArgs e)
    {
        if (listBoxDailyCases.SelectedItems.Count <= SEVEN)
        {
            double average = listBoxDailyCases.SelectedItems.Count / SEVEN;

            labelOutputDailyAverage.Text.Show(+average);
        }
        else
        {
            MessageBox.Show("Please enter a only 7 case count numbers");
        }
    }
}
公共部分类formAverageWeeklyCases:表单
{ 
int七=7;
公共形式平均每周案例()
{
初始化组件();
}
私有无效按钮单击(对象发送者,事件参数e)
{
Application.Exit();
}
私有无效按钮输入\单击(对象发送者,事件参数e)
{
如果(textBoxCaseEntry.Text.Trim().Length>=1)
{
listBoxDailyCases.Items.Add(textBoxCaseEntry.Text.Trim());
textBoxCaseEntry.Text=string.Empty;
textBoxCaseEntry.Focus();
}
其他的
{
MessageBox.Show(“输入的号码似乎无效”);
textBoxCaseEntry.Text=string.Empty;
textBoxCaseEntry.Focus();
}
}
私有无效按钮重置单击(对象发送者,事件参数e)
{
textBoxCaseEntry.Text=string.Empty;
listBoxDailyCases.Items.Clear();
labelOutputDailyAverage.Text=string.Empty;
}
私有void textBoxAverageWeeklyCases\u TextChanged(对象发送方,事件参数e)
{

如果(listBoxDailyCases.SelectedItems.Count)我理解正确,您想从用户那里收集7个数字,然后计算平均值?如果是,我建议您声明一个整数列表(如果需要双倍,则为双倍),然后调用
TryParse
验证用户输入,然后在需要时计算平均值:


公共部分类formAverageWeeklyCases:表单
{
const int SEVEN=7;
私有列表编号=新列表(七);//新
公共形式平均每周案例()
{
初始化组件();
}
私有无效按钮单击(对象发送者,事件参数e)
{
Application.Exit();
}
私有无效按钮输入\单击(对象发送者,事件参数e)
{
if(int.TryParse(textBoxCaseEntry.Text.Trim(),out int parsed))//新建
{
number.Add(已解析);//新建
textBoxCaseEntry.Text=string.Empty;
textBoxCaseEntry.Focus();
}
其他的
{
MessageBox.Show(“输入的号码似乎无效”);
textBoxCaseEntry.Text=string.Empty;
textBoxCaseEntry.Focus();
}
}
私有无效按钮重置单击(对象发送者,事件参数e)
{
textBoxCaseEntry.Text=string.Empty;
listBoxDailyCases.Items.Clear();
labelOutputDailyAverage.Text=string.Empty;
}
私有void textBoxAverageWeeklyCases\u TextChanged(对象发送方,事件参数e)
{
如果(listBoxDailyCases.SelectedItems.Count