Как объявить глобальную переменную? - C#
Формулировка задачи:
Как объявить глобальную переменную?у меня 16 блоков и нужно чтобы она была доступна всем блокам
В С#.
Решение задачи: «Как объявить глобальную переменную?»
textual
Листинг программы
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
{
#region Инициализация массива
button1.Text = "к";
button2.Text = "р";
button3.Text = "а";
button4.Text = "т";
button5.Text = "н";
button6.Text = "а";
button7.Text = "н";
button8.Text = "а";
button9.Text = "е";
button10.Text = "б";
button11.Text = "о";
button12.Text = "н";
button13.Text = "м";
button14.Text = "а";
button15.Text = "ш";
button16.Text = "и";
button17.Text = "Проверить";
#endregion
string[] slova = { "кран", "небо", "машина" };
button17.Click += (sender, e) =>
{
foreach (string str in slova)
if (textBox1.Text == str) MessageBox.Show("Вы собрали слово " + str);
};
foreach (Control control in this.Controls)
{
Button b = control as Button;
if (b != null && b.Text != "Проверить")
{
b.Click += delegate(System.Object o, EventArgs e)
{
textBox1.Text += ((ButtonBase)(o)).Text;
};
}
}
}
}
}
}