C# 记分板-将分数添加到主记分板-不工作

C# 记分板-将分数添加到主记分板-不工作,c#,C#,我正在尝试将分数添加到当前分数,因此当我们打印输出时,我希望将较早的分数添加到+1,然后将其相加并打印新分数。这不起作用,我尝试了很多选择,我如何解决这个问题集?我得到的输出是1,与第一个结果后显示的输出相同 namespace scoreboard { public partial class Form1 : Form { public Form1() { InitializeComponent(); }

我正在尝试将分数添加到当前分数,因此当我们打印输出时,我希望将较早的分数添加到+1,然后将其相加并打印新分数。这不起作用,我尝试了很多选择,我如何解决这个问题集?我得到的输出是1,与第一个结果后显示的输出相同

namespace scoreboard
{

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public double regnut()
        {
            int score = 0;
            return score = score + 1;
        }
        private void button1_Click(object sender, EventArgs e)
        {

            string input = textBox1.Text;

            int score;
            count();




        }
        void count()
        {
            string iny = textBox1.Text;
            double score = 0;

            if (iny == "t")
            {
                score = score + 1;
                listBox1.Items.Add(score);
            }
            label1.Text = "Score: " + score;
        }


    }
}

这是因为您总是将
分数
初始化回零。您需要有一个变量来保存
分数的当前值。示例如下:

private int currentScore = 0; // holds you current Score value

void count()
{
    string iny = textBox1.Text;
    int score = currentScore; // sets initial value based from the current Score
    if (iny == "t")
    {
        score = score + 1; // increment value
        listBox1.Items.Add(score);
    }

    currentScore = score; // store the value in the variable
    label1.Text = "Score: " + currentScore.ToString();
}