-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathValidWords.cs
executable file
·50 lines (45 loc) · 1.59 KB
/
ValidWords.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
namespace WordGame
{
using System.Collections;
using System.IO;
using System.Reflection;
public class ValidWords : IValidWords
{
// As all word are different it's better to use HashSet because it's faster (O(1))
ArrayList a = new ArrayList();
public ValidWords()
{
Stream stream = null;
StreamReader reader = null;
try
{
// not sure if using reflection here is a good idea. it would be much cleaner to put path in configuration file
// and use FileStream
stream = Assembly.GetAssembly(typeof(ValidWords)).GetManifestResourceStream("WordGame.wordlist.txt");
reader = new StreamReader(stream);
while (!reader.EndOfStream)
{
a.Add(reader.ReadLine());
}
}
// I guess it would be better to add 'catch' block as well, because right now all exceptions are being ignored
finally
{
// please use 'using' constructions instead
reader.Dispose();
stream.Dispose();
}
}
// it's totally ok to write this thing like that,
// but there is one-liner that do exactly the same (just for you tho know):
// public int Size => a.Count;
public int Size
{
get { return a.Count; }
}
public bool Contains(string word)
{
return a.Contains(word);
}
}
}