Im very new to c# and programming in general, so I apologise if this seems a very daft and simple question. Im trying to create a simple program where clicking a button will bring up a message box, randomly selecting a single word from a simple list of half a dozen words. After 3 days of googling and scrolling through pages on pages I'm more than a little stumped on how I can define the random variable correctly so that I can have the variable show on the message box.
I want to use testvar as the defined variable just while Im learning.
Heres my code as it stands, around the random list and I would be very appreciative if someone could point me in the right direction or give me some advice.
//random generator list for adjectives
Random r = new Random();
string[] words = { "tall", "short", "slim", "chunky", "donkey", "Ice cream" };
Console.WriteLine(words[r.Next(0, words.Length)]);
var testvar = ??? ;
I'm fairly confident Ive got the button coding right, but I thought Id include that as well so it can be seen. Again sorry for what is most likely a dumb and noob question
private void Generate_Click(object sender, RoutedEventArgs e)
{
// Generate box results - need to get varible right from list
MessageBox.Show("You have selected " + testvar + Environment.NewLine + Environment.NewLine + "Congratulations", "Results");
}
Aucun commentaire:
Enregistrer un commentaire