You could use reflection for this, but it might be overkill for this scenario.
If you are simply setting all variables to true, you might want to just set them on the source.
bool Q1Button1_True = true;
bool Q2Button1_True = true;
bool Q3Button1_True = true;
bool Q4Button1_True = true;
Also, if this is something that will grow, let's say to Qn
then you might want to have an array, where instead of Q1Button1_True
you would have Button1_True[1]
.
I am assuming you will be doing this is multiple parts of your application, so it might be a wise choice to have some "dynamic" setters. In this case, you can use reflection:
bool Q1Button1_True, Q2Button1_True, Q3Button1_True, Q4Button1_True;
List<string> radioBtns = new List<string>(new string[] { "Q1Button1_True", "Q2Button1_True", "Q3Button1_True", "Q4Button1_True" });
foreach (string Btn in radioBtns)
{
bool buttonVar = this.GetType().getProperty(Btn).getValue(this, null);
buttonVar = true;
}
Another way of doing it is to use something like this:
bool Q1Button1_True, Q2Button1_True, Q3Button1_True, Q4Button1_True;
List<string> radioBtns = new List<string>(new string[] { "Q1Button1_True", "Q2Button1_True", "Q3Button1_True", "Q4Button1_True" });
foreach (string Btn in radioBtns)
{
PropertyInfo buttonVar = this.GetType().GetProperty(Btn);
buttonVar.SetValue(this, true, null);
}
Hope this helps!