public void AcceptVisitorExample() { var sortedList = new SortedList <string> { "cat", "dog", "canary" }; // There should be 3 items in the sortedList. Assert.AreEqual(3, sortedList.Count); // Create a visitor that will simply count the items in the sortedList. var visitor = new CountingVisitor <string>(); // Make sortedList tree call IVisitor<T>.Visit on all items contained. sortedList.AcceptVisitor(visitor); // The counting visitor would have visited 3 items. Assert.AreEqual(3, visitor.Count); }