Going Round and Round
The Coding CraftsmanDid you think iteration was simple? Well, there’s more than one way to do it. For this example, let’s imagine we have a class called Provider. Let’s imagine it has a Get function which either returns the next item or returns null when there are none left. How would you empty this provider and add all its objects to a list or concatenate them in a string? We saw some code which looked like this // append to StringBuilder StringBuilder builder = new StringBuilder(); while (true) { string next = provider.Get(); // get next if (next == null) { break; } builder.Append(next); // append } The old while-true solution. It just looks wrong. In the code we saw, there was a little more to the “GetNext” and the “Append” lines, so it looked worse. Surely there are other ways of doing it? Well, let’s have a look at some. Firstly we need a testable provider: /// <summary> /// A simple provider that will return C, B, A and then nulls /// </summar







