Answer the question
In order to leave comments, you need to log in
How to create a public instance of a class?
I need to create an instance of the Equipment class that will be available throughout the solution, how can I do this? It should be created on the button.
Here is the current definition:
private void btnOk_Click(object sender, EventArgs e)
{
lblCurrentRun.Text = $"Текущий заход: {txtRunCount.Text}";
Equipment eq = new Equipment();
eq.countRun = Int32.Parse(txtRunCount.Text);
}
private void btnHelmAdd_Click(object sender, EventArgs e)
{
int countRun = Int32.Parse(new string(lblCurrentRun.Text.Where(Char.IsDigit).ToArray()));
MessageBox.Show($"Текущий забег: {countRun}");
eq.Boots = txtHelmSelect.Text;
}
Answer the question
In order to leave comments, you need to log in
Do you have code similar to WinForms?
- make a field Equipment eq = default;
in the form
- eq = new Equipment();
in btnOk_Click
but not a fact, maybe you can initialize it right away
- btnHelmAdd_Click
you can use it. in fact, if you initialize (assign an instance by ) in the form constructor, then you can use psnew
anywhere , everything that has been said is true until you grow up to multithreading
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question