imagine this code
for (int iDay = 1; iDay <= total_days; iDay++)
{
question = CheckString(s.challenge_1_q);
answer = CheckStringA(s.challenge_1_a);
// more here
}
but what I really have is from challenge_1_q to challenge_24_q and challenge_1_a to challenge_24_a
what is my best option to have dynamic variables as today it’s 24, “tomorrow” could be only 18.
is the use of dynamic the proper way? or I really need to have a switch and forget about dynamism ?
Create a class called QuestionAnswer, then store a List on s.
The accessing code will look like this:
The QuestionAnswer class:
And the definition on your existing class:
Instead of having dozens of variables, you add dozens of items to the list: