WordCount Application Sample
This sample shows how to create an application that opens multiple files and counts each file's bytes, characters, words, and lines. The results from each file and the total of all files are displayed.
For information about using the samples, see the following topics:
To build the sample using the command prompt
Open the Command Prompt window and navigate to one of the language-specific subdirectories under the WordCount directory. For information about required settings and the SDK Command Prompt, see How to: Set Sample Settings.
Type msbuild WordCountCS.sln or msbuild WordCountVB.sln, depending on your choice of programming language.
To build the sample using Visual Studio
Open Windows Explorer and navigate to one of the language-specific subdirectories under the WordCount directory.
Double-click the WordCountCS.sln or WordCountVB.sln file, depending on your choice of programming language, to open the file in Visual Studio 2005.
On the Build menu, click Build Solution.
To run the sample
In the Command Prompt window, navigate to the subdirectory that contains the WordCount application.
Type WordCount.exe [filename] at the command prompt to count the words in a file.
The totals from each file are listed separately and the total of the results from all the files are displayed.
Remarks
The sample is a console application; you must run it from the command line to view its output.
The sample uses the following technologies and classes:
I/O -
FileStream - Allows file access. This class is used to read to and write from files.
StreamWriter - Used with a FileStream instance to format text output to a file.
StreamReader - Used with a FileStream instance to read text from a file.
Collections -
ArrayList - Stores sets of objects.
SortedList - Stores sets of objects in a sorted manner.
IEnumerator - Enumerates over sets of objects.
IDictionaryEnumerator - Enumerates over indexed sets of objects.
See Also
Reference
ArrayList Class
FileStream Class
IEnumerator Interface
SortedList Class
StreamReader Class
StreamWriter Class
System.Collections Namespace
System.IO Namespace
IDictionaryEnumerator
Concepts
.NET Framework Class Library Overview