1  using System;
   2  using System.IO;
   3  
   4  class WordList {
   5      public WordList(string file) {
   6          // Get number of words:
   7          int numberOfWords = 0;
   8          using (StreamReader reader = new StreamReader(file))
   9              while (reader.Peek() >= 0)
  10              {
  11                 reader.ReadLine();
  12                 ++numberOfWords;
  13              }
  14  
  15          wordList_ = new string[numberOfWords];
  16  
  17          // Read words into array:
  18          using (StreamReader reader = new StreamReader(file))
  19              for(int k = 0; k<numberOfWords; ++k) wordList_[k] = reader.ReadLine();
  20          }
  21  
  22      public WordList(WordList wordList) { // NOT COPY CTOR -- removes first word
  23          int length = wordList.wordList_.Length - 1;
  24          if (length <= 0) new Exception("Error:  Attempt to shorten WordList having only one word.");
  25          wordList_ = new string[length];
  26          for (int k = 0; k < length; ++k) 
  27              wordList_[k] = wordList.wordList_[k + 1];
  28          }        
  29  
  30      public bool hasOnlyOneWord() {return wordList_.Length==1;}
  31  
  32      public string firstWord() {return wordList_[0];}
  33  
  34  /*  // Not used.  For reference only:
  35      public int maxLength() {
  36          int length = 0;
  37          wordList_.ForEach(delegate(Word word) 
  38              {if(word.word_.Length > length) length = word.word_.Length;});
  39          return length;
  40          }*/
  41  
  42      // ======= Data Members ========
  43      private string[] wordList_;
  44  }
  45