How to Turn a Randomized String Array 'word' into an array made up of the string's Characters C#? -


okay, i'm creating hang-man game (lame, know, gotta' start somewhere). have pulled ~30 random words text file variable , can display word in random order onto screen (just test , make sure variable obtaining whole word in random order).

but need take string , break single characters in order 'blank' out letters 'guessed' user. assume array best way - coupled while loop run while character != null.

using system; using system.collections.generic; using system.io; using system.linq; using system.text; using system.threading.tasks;  namespace hangman { class program {     static void main(string[] args)     {         string[] mywordarrays = file.readalllines("wordlist.txt");         random randomword = new random();         int linecount = file.readlines("wordlist.txt").count();                     int activeword = randomword.next(0, linecount);          /*charenumerator activewordchar = activeword; --- have tried this,          says "cannot implicitly convert type 'int' 'system.charenumerator'          --- while redlining "activeword." */          /*charenumerator activewordchar = activeword.tostring          -- have tried says "cannot convert method group 'tostring'          non-delegate type 'system.charenumerator'. did intend invoke method?           tried moving declaration of activewordchar below 'writeline'           displays word console.            have tried create char[] activewordchar = activeword.tochararray; doesn't work either.           */                      //i'm using writeline "the word game is: " test          //system choosing random word **end comment          console.writeline("the word game is: " + mywordarrays[activeword]);            //console.writeline("the characters this: " + activewordchar[]);          //my attempt @ printing something, doesn't work. :(         console.readline();       }     } } 

i'm open references in order figure out myself, i'm kinda' stuck here.

also, how close file i've opened can accessed later on in program if need be? i've learned streamreader("filename") way of 'variable.close();' - isn't working here.

edit

and why vote question down beyond me. lol

a couple of points here (first of all, off great start):

  1. you needlessly re-reading file line count. can use mywordarrays.length set linecount variable
  2. regarding question closing file, per msdn file.readalllines() closes file after done reading it, fine there have.

a string can treated array in terms of accessing index , accessing length property. there's ability iterate on implicitly so:

foreach (char letter in mywordarrays[activeword]) { // provide blanked-out letter each char } 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -