Although the following question has been partly answered a number of times over the past decade, C# has changed significantly in the past few years to include better constructs for handling events, tasks, and the like. What is the current best suggested way to convert the following procedural code into code appropriate for a form, i.e., code to avoid busy waiting and keeping the computer responsive? Please provide complete code. I have found that mere suggestions usually require a lot more follow up for full understanding.
The form consists of a textbox (NameBox) where the name is displayed and two buttons (ButtonM and ButtonF) labeled "Male" and "Female" which when pressed do the functions described below. I've left out any declaration of the buttons since their definition is part of the solution I hope you can provide.
public class Question
{
static string[] names = {"Steve", "Lois", "Doug"};
static char[] genders = new char[names.Length];
public static void GetGenders (string[] names)
{
// Something 1
for (int i = 0; i < names.Length; i+) {
NameBox.Text = names[i];
// Wait for user to press Male or Female button;
// if (ButtonM pressed) genders[i] = 'M';
// if (ButtonF pressed) genders[i] = 'F';
}
// Something 2
}
}
Thanks for your time and effort.