c# - How do I actually store the randomly chosen word as a word? -


so working on hangman program. pull list of 126 different words , randomly select 1 of words. output "_" each character.

but now, when i'm trying determine 'correct guess' of word, can't figure out how store value of randomly chosen word. sounds funny, have you. lol.

string[] mywordarrays = file.readalllines("wordlist.txt");         random randomword = new random();         //int linecount = file.readlines("wordlist.txt").count();                     int activeword = randomword.next(0, mywordarrays.length);         string userselection = "";          console.writeline("are ready play hangman? yes/no: ");          userselection = console.readline();             if(userselection == "yes")             {                  foreach(char letter in mywordarrays[activeword])                 {                      //the console.write(activeword) shows line number o.0.                      //when try print out .write(mywordarrays) shows                      //system.(something) on screen. ugh.                      console.write(activeword);                     console.write("_ ");                  } 

i believe code needs referenced code deals choosing of random word. i'm baffled this. i've tried set different things active word , can't think of logical way have 'foreach' place each letter array (which beneficial later when i'm ready search each letter when user guesses letter).

the line says

int activeword = randomword.next(0, mywordarrays.length); 

change to

string activeword = mywordarrays[randomword.next(0, mywordarrays.length)]; 

and change foreach to

foreach(char letter in activeword) 

and don't need have foreach put word char array. when need char array, can say

activeword.tochararray() 

but won't need string ienumerable, means can foreach on string, without turning array, did above.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -