Your "PartOfSpeech TranslatePart(string part)" method can be reduced to a much more simple method:
That will do a case insensitive parse of your string and give you the corresponding enum type. If the string is not part of the enum, you'll get Unknown.Code:PartOfSpeech TranslatePart(string part) { if (Enum.IsDefined (typeof (PartOfSpeed), part)) return (PartOfSpeed) Enum.Parse (typeof (PartOfSpeed), part, true); return PartOfSpeech.Unknown; }
You do a few funny things like calling ElementAt instead of directly accessing the element at the index:
The difference being that you're invoking Linq extension methods which operate on IEnumerable. This means that to get the element at position [i], the LINQ method might do something like:Code:Word currentWord = this.ElementAt(i); // should be Word currentWord = this [i];
Similarly for your usage of the LINQ method "Count ()" instead of directly using the List<T> property 'Count'.Code:public T ElementAt (int index) { int count = 0; foreach (var v in this) { if (count == index) return v; count ++; } }
Most of your 'MatchesXXX' methods can be rewritten to be like this:
Alternatively if 'texts' were a List<string> instead of a string[] you could just directly call: "texts.Contains (Text)" and remove that method entirely. Or just change your method signature to accept an IList<string>. Both string[] and List<string> implement IList<string>, so you can access your string[] through the IList<string> interface and gain easy access to methods like IndexOf and Contains.Code:public bool MatchesText(string[] texts) { return Array.Contains<string> (texts, Text); }
For example it's perfectly legal to declare your method like this and pass a string[] as the parameter:
You use turnary when you don't have to in a few places, for example:Code:public WordList ThoseWithStress(IList<string> stresses) { WordList newList = new WordList(); for (int i = 0; i < this.Count; i++) { if (stresses.Contains (this [i])) newList.Add(new Word(this [i])); } return newList; } ... ... ThoseWithStresses (new string[] { "u" });
can be simply:Code:return NumberOfSyllables > 0 ? true : false;
The UpdateRandomizer function is completely unnecessaryCode:return NumberOfSyllables > 0;You can't make things *more* random by creating a new Random object. The only thing you'd be likely to do would be to make things *less* random
Just remove that code and your app will instantly become better and shorter!
Other than that, things look more pretty decent. I'd have no major complaint about it, most of the issues I have are just minor ones.




You can't make things *more* random by creating a new Random object. The only thing you'd be likely to do would be to make things *less* random
Just remove that code and your app will instantly become better and shorter!
Reply With Quote
