jeudi 7 janvier 2016

How to add a random answer to a radio button

I am looking to add a piece of code that adds a random answer to a radiobutton but I just cant figure out how to get it to add to the radiobutton so that each time you load it displays a different answer.

How may I go about doing this to get it to work?

The code I have used so far:

List<string> answers = new List<string>();
answers.Add("1 Byte");
answers.Add("1 KiloByte");
answers.Add("1 PetaByte");
answers.Add("1 MegaByte");

Random rnd = new Random();
string[] MyRandomArray = answers.OrderBy(x => rnd.Next()).ToArray();

List<RadioButton> rbs = new List<RadioButton>();
rbs.Add(rb1);
rbs.Add(rb2);
rbs.Add(rb3);
rbs.Add(rb4);

foreach (string s in MyRandomArray)
{
    rbs.Add(s.ToString())
}

Any help would be greatly appreciated

Thanks




Aucun commentaire:

Enregistrer un commentaire