在 c# 中存储数字项目



例如查看网站和要求。

这是我到目前为止所拥有的:

        private void Form2_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.DialogResult = DialogResult.OK;
        }
            private void button1_Click(object sender, EventArgs e)
    {
        textBox1.Clear();
        input++;
        MessageBox.Show(input.ToString());
    }        
}

由于这看起来像家庭作业,我只给你指示。否则你不会学到。

1 - On Form1, once the button to open Form2 is clicked, make sure you do Form1.Hide() or Form1.Visible = false, and ppen Form2.
2 - In Form2 there is a textbox and a button.
3 - Once that button is clicked, get the text of the textbox, and split it by "space" to get an array of numbers, MyArray.
4 - Finally, display a MessageBox containing MyArray.Length;
5 - Form2.Hide(), Form1.Show()

哦,我没有提到 Form1 和 Form2 应该是静态的。

这就是OP正在寻找的,对吧?

首先,你应该向你的老师寻求帮助。他可能是个好人,我敢肯定他今天在教室里走来走去,寻找学生的帮助。我相信你的老师甚至可能已经建立了一个课堂论坛,也许使用像Piazza这样的网站,在那里你可以向你的同学寻求帮助,这可能更有用,因为你的同学会有更好的背景这个项目。这里的人愿意提供帮助,但是当你甚至还没有了解数组时,他们的一些帮助可能没有用。

话虽如此,看起来您已经有了存储输入数字计数的代码。输入变量应在类的顶部声明,在按钮中递增它,然后在 MessageBox 中显示它。但是,MessageBox 应在窗体关闭时显示,因此请确保该部分位于 FormClosing 事件处理程序中。

我希望这有帮助,达里安。

你能做一个每次输入数字时递增的全局变量吗?

如果您想获取用户输入了多少个数字。例如:- 如果用户输入 100 50 90。然后只需将文本框的内容放入数组中(必须需要间距)。然后声明一个全局变量 整数计数=0;然后在 for 循环中。
for(int i=0;i<length_of_array;i++) { if(your_array[i]==' ') count++; } MessageBox.Show("There are "+count+" numbers");

这就是全部!!

最新更新