我想知道如何在程序期间保存用户输入。
我的代码:
struct client
{
public string points;//to collect the points from a textbox
public int x;//variable used to temporarily save the input from the textbox
public int will;//used to store his points until the end of the program
public int steph;//used to store here points until the end of the program
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button3_Click(object sender, EventArgs e)
{
client ob = new client();//instance of client
ob.points = textBox1.Text;
ob.x = Convert.ToInt32(ob.points);//conversion
MessageBox.Show(ob.x.ToString());//used to confirm points
button1.Enabled = true;//enables button to show where the points should go
button2.Enabled = true;
}
private void button1_Click(object sender, EventArgs e)
{
client ob = new client();
ob.points = textBox1.Text;
ob.x = Convert.ToInt32(ob.points);
ob.will = ob.will + ob.x;
MessageBox.Show(ob.will.ToString());//actually adding the points to him
}
private void button2_Click(object sender, EventArgs e)
{
client ob = new client();
ob.points = textBox1.Text;
ob.x = Convert.ToInt32(ob.points);
ob.steph = ob.steph + ob.x;// actually adding the points to her
MessageBox.Show(ob.steph.ToString());
}
}
有人告诉我我需要添加我的客户的三个实例,但这就是他们给我的所有信息。当您告诉我时,请您深入回答。另外,如果有办法使代码更高效,请告诉我。