I'm quite new to coding in c# and i'm having difficulty assigning properties to a random textbox from an array. Here is the code i am using:
TextBox[] peopletiles = { A2, A3, A4, A5,};
int totalpeople = 0;
do
{
Random random = new Random();
int tile = random.Next(0, peopletiles.Length);
tile.BackColor = Color.Purple;
totalpeople += 1;
} while (totalpeople != Edit.peopleStart);
I'm trying to change the colour of a random textbox from the array "peopletiles" to purple and have this looped until the number of purple text boxes is equal to the value of "Edit.peopleStart"
Using the code above gives the error "'int' does not contain a definition for 'BackColor'"
new Random()inside your loop.Randomis seeded by the system clock, so when instantiated in a hard loop, it will produce the same number for quite a few iterations. Try moving theRandom random = new Random();before thedoloop.