我是C#的初学者,很难解决我们的一些问题。所以我希望我的术语无所谓。这是我的问题。假设我有以下代码:
namespace WindowsFormsApplication8
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//code starts
//...
//if(...) {
//...
//string parameter = abc.ToString();
//}
//code ends
}//Form1 ends
private void button1_Click(object sender, EventArgs e)
{
//code here
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = parameter;
button1.Perform();
}
}
}
我在这里遇到困难。
如何在Form1
内使用名为parameter
的{{1}}中声明的字符串?
button2_Click
不起作用。
答案 0 :(得分:2)
使用成员变量。
public partial class Form1 : Form
{
private string parameter = null;
public Form1()
{
InitializeComponent();
// ...
parameter = abc.ToString();
}