【发布时间】:2018-10-16 03:56:32
【问题描述】:
我正在尝试从其他函数访问变量。但是,当我尝试将函数中的变量公开或静态时,到处都会弹出错误(尤其是公开的)。这是我的代码。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
string f = textBox1.Text;
label6.Text = f;
label9.Text = f;
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
string n = textBox2.Text;
label14.Text = n;
}
private void textBox6_TextChanged(object sender, EventArgs e)
{
}
}
有人知道我如何在 textBox6 方法中访问 f 或 n 吗?
【问题讨论】:
-
你想在哪里访问哪个函数的哪个变量?函数不能有带有访问修饰符的变量,例如 public。