c# - Variable definition issue -


im new c# , programming in general, apologise if seems daft , simple question. im trying create simple program clicking button bring message box, randomly selecting single word simple list of half dozen words. after 3 days of googling , scrolling through pages on pages i'm more little stumped on how can define random variable correctly can have variable show on message box.

i want use testvar defined variable while im learning.

heres code stands, around random list , appreciative if point me in right direction or give me advice.

    //random generator list  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 confident ive got button coding right, thought id include can seen. again sorry dumb , noob question

 private void generate_click(object sender, routedeventargs e)     {         // generate box results - need varible right list         messagebox.show("you have selected " + testvar + environment.newline + environment.newline + "congratulations", "results");     } 

this should work:

private void generate_click(object sender, routedeventargs e) {     random r = new random();      string[] words = { "tall", "short", "slim", "chunky", "donkey", "ice cream" };      messagebox.show("you have selected " + words[r.next(0, words.length - 1)] + environment.newline + environment.newline + "congratulations", "results"); } 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -