as the title say's I am attempting to get to edit a list item inside of a foreach loop. I know it is not possible, so I am asking for solutions to work around this.
As this is taking data directly from a MySQL server, it need's to be done inside of this loop and with the correct indexes. I attempted to use a second list and change the data outside of the foreach loop, but that did not account for the index positions of the items.
foreach (string friend in friendsOnline)
{
query = "SELECT `username` FROM `accounts` WHERE email = '" + friend + "'";
cmd = new MySqlCommand(query, conn);
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
for (int i = 0; i<friendsOnline.Count; i++)
{
if (friendsOnline[i].Contains(friend))
{
friendsOnline[i] = rdr[0].ToString();
}
}
}
}