Posts

Showing posts from July, 2005
Peeking at An Iterator C'mon, You Know You Want To I'm currently designing a set of classes that will be used for parsing and importing data. Being a devotee of Design Patterns , I am quite familiar with the Iterator pattern, and felt that it was the appropriate tool to apply to parsing rows in text-based files. Using an interator, rows could be parsed one character at a time, looking for field delimiters (for example, in comma delimited files, the field delimiter is a comma), and moving the data into into the appropriate field in a DataRow. Strings in .NET already have an iterator associated with them. Strings implement the IEnumerable interface (from the System.Collections namespace), and therefore have a method called GetEnumerator. String's GetEnumerator method returns an instance of the CharEnumerator class (again, in System.Collections). As the name suggests, it iterates through through the characters in the string. Iterators in .NET basically know 3 things: how to vi