I had to change addStick to use the add method for List to add a new Stick object to the list.
I though, for a while, that I could stop using true and false as values of a stick, but in the getStick method, I needed to return something other than null. Otherwise, when the calling code tried to use stick.Value, it gave an error.
I had noted that returning null was bad practice in the code comments.
To address this, I created a second constructor for Stick that accepts a boolean and sets the Value. That way, the code can return a "false" stick when there is no correct stick to return.
The next challenge will be removeStick. Changing this will involve using the remove method.
When I wrote getHashCode and Equals for these classes, I assumed I was just practicing, but List does use those methods for comparing objects in the remove method. (Well, unless the type implements the System.IEquatable
No comments:
Post a Comment