1 using System;
2 using System.IO;
3
4 class WordList {
5 public WordList(string file) {
6
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
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) {
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
35
36
37
38
39
40
41
42
43 private string[] wordList_;
44 }
45