December 2001
Intermediate to advanced
416 pages
8h 16m
English
As the lines of text are read from the file, I prefer to store them rather than process them immediately. A string array would be the container of choice to do this, but the C# array is a fixed-size container. The required size varies with each text file that is opened, so the C# array is too inflexible.
The System.Collections namespace provides an ArrayList container class that grows dynamically as we either insert or delete elements. For example, here is our earlier read loop revised to add elements to the container:
using System.Collections; private void readFile() { ArrayList m_text = new ArrayList(); string text_line; while (( text_line = m_reader.ReadLine() ) != null ) { if ( text_line.Length ...Read now
Unlock full access