Geeks With Blogs
Robert's Blog ideas about design and development December 2007 Entries
Writing a Linked List: Then vs Now (part 3)
Now that we've implemented the indexers, we'll move on to implementing the CopyTo method. Lets write a test for that. [Test] public void CopyToWorks() { list.Add(name); list.Add(name1); string[] names = new string[list.Count]; list.CopyTo(names, 0); Assert.IsTrue(names[0].Equa... Assert.IsTrue(names[1].Equa... } Let's take the next step and implement CopyTo public void CopyTo(T[] array, int arrayIndex) { int index = arrayIndex; foreach (T item in this) { array[index] = item; index++; ......

Posted On Saturday, December 22, 2007 9:03 AM

Writing a Linked List: Then vs Now (part 2)
Now that insert is fully functional, we are going to want to implement RemoveAt. [Test] public void RemoveAtWorks() { list.Add(name); list.Add(name1); string name2 = "James"; list.Add(name2); list.RemoveAt(1); enumerator.MoveNext(); enumerator.MoveNext(); Assert.IsTrue(enumerator.Cu... } That test looks pretty good. Now let's go implement RemoveAt. public void RemoveAt(int index) { int position = -1; MyListNode<T> node = null; if (index == 0) RemoveFirst(); else if (index ......

Posted On Friday, December 21, 2007 6:59 AM

Copyright © Robery Stackhouse | Powered by: